1
0
mirror of https://github.com/Yubico/yubikey-ksm.git synced 2024-11-28 15:24:15 +01:00

Case insensitive.

This commit is contained in:
Simon Josefsson 2009-12-14 16:18:38 +00:00
parent 9be8b3bbc8
commit c42876cce9
5 changed files with 34 additions and 34 deletions

View File

@ -1,15 +1,15 @@
create table yubikeys (
-- identities:
serialNr int not null,
publicName varchar(16) unique not null,
serialnr int not null,
publicname varchar(16) unique not null,
-- timestamps:
created varchar(24) not null,
-- the data:
internalName varchar(12) not null,
aesKey varchar(32) not null,
lockCode varchar(12) not null,
internalname varchar(12) not null,
aeskey varchar(32) not null,
lockcode varchar(12) not null,
-- key creator, typically pgp key id of key generator
creator varchar(8) not null,
@ -18,5 +18,5 @@ create table yubikeys (
active boolean default true,
hardware boolean default true,
primary key (publicName)
primary key (publicname)
);

View File

@ -55,8 +55,8 @@ try {
die("ERR Database error\n");
}
$sql = "SELECT aesKey, internalName FROM yubikeys " .
"WHERE publicName = '$id' AND active";
$sql = "SELECT aeskey, internalname FROM yubikeys " .
"WHERE publicname = '$id' AND active";
$result = $dbh->query($sql);
if (!$result) {
syslog(LOG_ERR, "Database query error. Query: " . $sql . " Error: " .
@ -70,15 +70,15 @@ if ($result->rowCount() != 1) {
}
$row = $result->fetch(PDO::FETCH_ASSOC);
$aesKey = $row['aesKey'];
$internalName = $row['internalName'];
$aeskey = $row['aeskey'];
$internalname = $row['internalname'];
$ciphertext = modhex2hex($modhex_ciphertext);
$plaintext = aes128ecb_decrypt($aesKey, $ciphertext);
$plaintext = aes128ecb_decrypt($aeskey, $ciphertext);
$uid = substr($plaintext, 0, 12);
if (strcmp($uid, $internalName) != 0) {
syslog(LOG_ERR, "UID error: $otp $plaintext: $uid vs $internalName");
if (strcmp($uid, $internalname) != 0) {
syslog(LOG_ERR, "UID error: $otp $plaintext: $uid vs $internalname");
die("ERR Corrupt OTP\n");;
}

View File

@ -79,7 +79,7 @@ if ($#ARGV>=0) {
my $dbh = DBI->connect($db, $dbuser, $dbpasswd, {'RaiseError' => 1});
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;
$sth->execute()
or die "Couldn't execute statement: " . $sth->errstr;
@ -93,11 +93,11 @@ while ($row = $sth->fetchrow_hashref()) {
}
print "\n";
}
print $row->{'serialNr'} . ",";
print $row->{'publicName'} . ",";
print $row->{'internalName'} . ",";
print $row->{'aesKey'} . ",";
print $row->{'lockCode'} . ",";
print $row->{'serialnr'} . ",";
print $row->{'publicname'} . ",";
print $row->{'internalname'} . ",";
print $row->{'aeskey'} . ",";
print $row->{'lockcode'} . ",";
print $row->{'created'} . ",\n";
}

View File

@ -118,8 +118,8 @@ die "Input not signed?" if !$signed_by;
my $dbh = DBI->connect($db, $dbuser, $dbpasswd, {'RaiseError' => 1});
my $inserth = $dbh->prepare_cached(qq{
INSERT INTO yubikeys (creator, created, serialNr,
publicName, internalName, aesKey, lockCode)
INSERT INTO yubikeys (creator, created, serialnr,
publicname, internalname, aeskey, lockcode)
VALUES (?, ?, ?, ?, ?, ?, ?)
});
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";
while (<GPGV>) {
next if m:^#:;
my ($serialNr, $publicName, $internalName, $aesKey,
$lockCode, $created, $accessed) =
my ($serialnr, $publicname, $internalname, $aeskey,
$lockcode, $created, $accessed) =
m%^([0-9]+),([cbdefghijklnrtuv]+),([0-9a-f]+),([0-9a-f]+),([0-9a-f]+),([T:0-9 -]*),([T:0-9 -]*)%;
if ($verbose) {
print "line: $_";
}
print "\tserialnr $serialNr publicName $publicName " .
"internalName $internalName aesKey $aesKey lockCode $lockCode " .
print "\tserialnr $serialnr publicname $publicname " .
"internalname $internalname aeskey $aeskey lockcode $lockcode " .
"created $created accessed $accessed eol";
if ($verbose) {
print "\n";
@ -148,9 +148,9 @@ while (<GPGV>) {
$created = $now if !$created;
$accessed = "NULL" if !$accessed;
$inserth->execute($creator, $created, $serialNr,
$publicName, $internalName,
$aesKey, $lockCode)
$inserth->execute($creator, $created, $serialnr,
$publicname, $internalname,
$aeskey, $lockcode)
or die "Database insert error: " . $dbh->errstr;
}
print "\n";

View File

@ -114,8 +114,8 @@ die "Input not signed?" if !$signed_by;
my $dbh = DBI->connect($db, $dbuser, $dbpasswd, {'RaiseError' => 1});
my $inserth = $dbh->prepare_cached(qq{
INSERT INTO yubikeys (creator, created, serialNr,
publicName, internalName, aesKey, lockCode)
INSERT INTO yubikeys (creator, created, serialnr,
publicname, internalname, aeskey, lockcode)
VALUES (?, NOW(), 0, ?, ?, ?, '000000000000')
})
or die "Couldn't prepare statement: " . $dbh->errstr;
@ -126,15 +126,15 @@ open(GPGV, "gpg < $infilename 2>/dev/null |")
or die "Cannot launch gpg";
while (<GPGV>) {
next if m:^#:;
my ($publicName, $aesKey, $internalName) =
my ($publicname, $aeskey, $internalname) =
m%^id ([cbdefghijklnrtuv]+) key ([0-9a-f]+) uid ([0-9a-f]+)%;
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;
$inserth->execute($creator, $publicName, $internalName, $aesKey)
$inserth->execute($creator, $publicname, $internalname, $aeskey)
or die "Database insert error: " . $dbh->errstr;
}