mirror of
https://github.com/Yubico/yubikey-ksm.git
synced 2024-11-29 00:24:14 +01:00
Case insensitive.
This commit is contained in:
parent
9be8b3bbc8
commit
c42876cce9
12
ykksm-db.sql
12
ykksm-db.sql
@ -1,15 +1,15 @@
|
|||||||
create table yubikeys (
|
create table yubikeys (
|
||||||
-- identities:
|
-- identities:
|
||||||
serialNr int not null,
|
serialnr int not null,
|
||||||
publicName varchar(16) unique not null,
|
publicname varchar(16) unique not null,
|
||||||
|
|
||||||
-- timestamps:
|
-- timestamps:
|
||||||
created varchar(24) not null,
|
created varchar(24) not null,
|
||||||
|
|
||||||
-- the data:
|
-- the data:
|
||||||
internalName varchar(12) not null,
|
internalname varchar(12) not null,
|
||||||
aesKey varchar(32) not null,
|
aeskey varchar(32) not null,
|
||||||
lockCode varchar(12) not null,
|
lockcode varchar(12) not null,
|
||||||
|
|
||||||
-- key creator, typically pgp key id of key generator
|
-- key creator, typically pgp key id of key generator
|
||||||
creator varchar(8) not null,
|
creator varchar(8) not null,
|
||||||
@ -18,5 +18,5 @@ create table yubikeys (
|
|||||||
active boolean default true,
|
active boolean default true,
|
||||||
hardware boolean default true,
|
hardware boolean default true,
|
||||||
|
|
||||||
primary key (publicName)
|
primary key (publicname)
|
||||||
);
|
);
|
||||||
|
@ -55,8 +55,8 @@ try {
|
|||||||
die("ERR Database error\n");
|
die("ERR Database error\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
$sql = "SELECT aesKey, internalName FROM yubikeys " .
|
$sql = "SELECT aeskey, internalname FROM yubikeys " .
|
||||||
"WHERE publicName = '$id' AND active";
|
"WHERE publicname = '$id' AND active";
|
||||||
$result = $dbh->query($sql);
|
$result = $dbh->query($sql);
|
||||||
if (!$result) {
|
if (!$result) {
|
||||||
syslog(LOG_ERR, "Database query error. Query: " . $sql . " Error: " .
|
syslog(LOG_ERR, "Database query error. Query: " . $sql . " Error: " .
|
||||||
@ -70,15 +70,15 @@ if ($result->rowCount() != 1) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$row = $result->fetch(PDO::FETCH_ASSOC);
|
$row = $result->fetch(PDO::FETCH_ASSOC);
|
||||||
$aesKey = $row['aesKey'];
|
$aeskey = $row['aeskey'];
|
||||||
$internalName = $row['internalName'];
|
$internalname = $row['internalname'];
|
||||||
|
|
||||||
$ciphertext = modhex2hex($modhex_ciphertext);
|
$ciphertext = modhex2hex($modhex_ciphertext);
|
||||||
$plaintext = aes128ecb_decrypt($aesKey, $ciphertext);
|
$plaintext = aes128ecb_decrypt($aeskey, $ciphertext);
|
||||||
|
|
||||||
$uid = substr($plaintext, 0, 12);
|
$uid = substr($plaintext, 0, 12);
|
||||||
if (strcmp($uid, $internalName) != 0) {
|
if (strcmp($uid, $internalname) != 0) {
|
||||||
syslog(LOG_ERR, "UID error: $otp $plaintext: $uid vs $internalName");
|
syslog(LOG_ERR, "UID error: $otp $plaintext: $uid vs $internalname");
|
||||||
die("ERR Corrupt OTP\n");;
|
die("ERR Corrupt OTP\n");;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -79,7 +79,7 @@ if ($#ARGV>=0) {
|
|||||||
|
|
||||||
my $dbh = DBI->connect($db, $dbuser, $dbpasswd, {'RaiseError' => 1});
|
my $dbh = DBI->connect($db, $dbuser, $dbpasswd, {'RaiseError' => 1});
|
||||||
my $sth = $dbh->prepare
|
my $sth = $dbh->prepare
|
||||||
('SELECT serialNr, publicName, internalName, aesKey, lockCode, created FROM yubikeys')
|
('SELECT serialnr, publicname, internalname, aeskey, lockcode, created FROM yubikeys')
|
||||||
or die "Couldn't prepare statement: " . $dbh->errstr;
|
or die "Couldn't prepare statement: " . $dbh->errstr;
|
||||||
$sth->execute()
|
$sth->execute()
|
||||||
or die "Couldn't execute statement: " . $sth->errstr;
|
or die "Couldn't execute statement: " . $sth->errstr;
|
||||||
@ -93,11 +93,11 @@ while ($row = $sth->fetchrow_hashref()) {
|
|||||||
}
|
}
|
||||||
print "\n";
|
print "\n";
|
||||||
}
|
}
|
||||||
print $row->{'serialNr'} . ",";
|
print $row->{'serialnr'} . ",";
|
||||||
print $row->{'publicName'} . ",";
|
print $row->{'publicname'} . ",";
|
||||||
print $row->{'internalName'} . ",";
|
print $row->{'internalname'} . ",";
|
||||||
print $row->{'aesKey'} . ",";
|
print $row->{'aeskey'} . ",";
|
||||||
print $row->{'lockCode'} . ",";
|
print $row->{'lockcode'} . ",";
|
||||||
print $row->{'created'} . ",\n";
|
print $row->{'created'} . ",\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -118,8 +118,8 @@ die "Input not signed?" if !$signed_by;
|
|||||||
|
|
||||||
my $dbh = DBI->connect($db, $dbuser, $dbpasswd, {'RaiseError' => 1});
|
my $dbh = DBI->connect($db, $dbuser, $dbpasswd, {'RaiseError' => 1});
|
||||||
my $inserth = $dbh->prepare_cached(qq{
|
my $inserth = $dbh->prepare_cached(qq{
|
||||||
INSERT INTO yubikeys (creator, created, serialNr,
|
INSERT INTO yubikeys (creator, created, serialnr,
|
||||||
publicName, internalName, aesKey, lockCode)
|
publicname, internalname, aeskey, lockcode)
|
||||||
VALUES (?, ?, ?, ?, ?, ?, ?)
|
VALUES (?, ?, ?, ?, ?, ?, ?)
|
||||||
});
|
});
|
||||||
my $now = strftime "%Y-%m-%dT%H:%M:%S", localtime;
|
my $now = strftime "%Y-%m-%dT%H:%M:%S", localtime;
|
||||||
@ -130,14 +130,14 @@ open(GPGV, "gpg < $infilename 2>/dev/null |")
|
|||||||
or die "Cannot launch gpg";
|
or die "Cannot launch gpg";
|
||||||
while (<GPGV>) {
|
while (<GPGV>) {
|
||||||
next if m:^#:;
|
next if m:^#:;
|
||||||
my ($serialNr, $publicName, $internalName, $aesKey,
|
my ($serialnr, $publicname, $internalname, $aeskey,
|
||||||
$lockCode, $created, $accessed) =
|
$lockcode, $created, $accessed) =
|
||||||
m%^([0-9]+),([cbdefghijklnrtuv]+),([0-9a-f]+),([0-9a-f]+),([0-9a-f]+),([T:0-9 -]*),([T:0-9 -]*)%;
|
m%^([0-9]+),([cbdefghijklnrtuv]+),([0-9a-f]+),([0-9a-f]+),([0-9a-f]+),([T:0-9 -]*),([T:0-9 -]*)%;
|
||||||
if ($verbose) {
|
if ($verbose) {
|
||||||
print "line: $_";
|
print "line: $_";
|
||||||
}
|
}
|
||||||
print "\tserialnr $serialNr publicName $publicName " .
|
print "\tserialnr $serialnr publicname $publicname " .
|
||||||
"internalName $internalName aesKey $aesKey lockCode $lockCode " .
|
"internalname $internalname aeskey $aeskey lockcode $lockcode " .
|
||||||
"created $created accessed $accessed eol";
|
"created $created accessed $accessed eol";
|
||||||
if ($verbose) {
|
if ($verbose) {
|
||||||
print "\n";
|
print "\n";
|
||||||
@ -148,9 +148,9 @@ while (<GPGV>) {
|
|||||||
$created = $now if !$created;
|
$created = $now if !$created;
|
||||||
$accessed = "NULL" if !$accessed;
|
$accessed = "NULL" if !$accessed;
|
||||||
|
|
||||||
$inserth->execute($creator, $created, $serialNr,
|
$inserth->execute($creator, $created, $serialnr,
|
||||||
$publicName, $internalName,
|
$publicname, $internalname,
|
||||||
$aesKey, $lockCode)
|
$aeskey, $lockcode)
|
||||||
or die "Database insert error: " . $dbh->errstr;
|
or die "Database insert error: " . $dbh->errstr;
|
||||||
}
|
}
|
||||||
print "\n";
|
print "\n";
|
||||||
|
@ -114,8 +114,8 @@ die "Input not signed?" if !$signed_by;
|
|||||||
|
|
||||||
my $dbh = DBI->connect($db, $dbuser, $dbpasswd, {'RaiseError' => 1});
|
my $dbh = DBI->connect($db, $dbuser, $dbpasswd, {'RaiseError' => 1});
|
||||||
my $inserth = $dbh->prepare_cached(qq{
|
my $inserth = $dbh->prepare_cached(qq{
|
||||||
INSERT INTO yubikeys (creator, created, serialNr,
|
INSERT INTO yubikeys (creator, created, serialnr,
|
||||||
publicName, internalName, aesKey, lockCode)
|
publicname, internalname, aeskey, lockcode)
|
||||||
VALUES (?, NOW(), 0, ?, ?, ?, '000000000000')
|
VALUES (?, NOW(), 0, ?, ?, ?, '000000000000')
|
||||||
})
|
})
|
||||||
or die "Couldn't prepare statement: " . $dbh->errstr;
|
or die "Couldn't prepare statement: " . $dbh->errstr;
|
||||||
@ -126,15 +126,15 @@ open(GPGV, "gpg < $infilename 2>/dev/null |")
|
|||||||
or die "Cannot launch gpg";
|
or die "Cannot launch gpg";
|
||||||
while (<GPGV>) {
|
while (<GPGV>) {
|
||||||
next if m:^#:;
|
next if m:^#:;
|
||||||
my ($publicName, $aesKey, $internalName) =
|
my ($publicname, $aeskey, $internalname) =
|
||||||
m%^id ([cbdefghijklnrtuv]+) key ([0-9a-f]+) uid ([0-9a-f]+)%;
|
m%^id ([cbdefghijklnrtuv]+) key ([0-9a-f]+) uid ([0-9a-f]+)%;
|
||||||
print "line: $_";
|
print "line: $_";
|
||||||
print "\tpublicName $publicName internalName $internalName aesKey $aesKey eol\n";
|
print "\tpublicname $publicname internalname $internalname aeskey $aeskey eol\n";
|
||||||
|
|
||||||
my $rows_changed = $dbh->do(q{UPDATE yubikeys SET publicName = ? WHERE publicName = ?}, undef, ("old-" . $publicName, $publicName))
|
my $rows_changed = $dbh->do(q{UPDATE yubikeys SET publicname = ? WHERE publicname = ?}, undef, ("old-" . $publicname, $publicname))
|
||||||
or die "Cannot update database: " . $dbh->errstr;
|
or die "Cannot update database: " . $dbh->errstr;
|
||||||
|
|
||||||
$inserth->execute($creator, $publicName, $internalName, $aesKey)
|
$inserth->execute($creator, $publicname, $internalname, $aeskey)
|
||||||
or die "Database insert error: " . $dbh->errstr;
|
or die "Database insert error: " . $dbh->errstr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user