Skip to content

Commit d35e465

Browse files
committed
a bit of cleanup
1 parent e6ebfec commit d35e465

4 files changed

Lines changed: 24 additions & 13 deletions

File tree

u2f-ref-code/java/src/com/google/u2f/server/impl/attestation/X509ExtentionParsingUtil.java renamed to u2f-ref-code/java/src/com/google/u2f/server/impl/attestation/X509ExtensionParsingUtil.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,14 @@
1111
/**
1212
* A set of utilities for parsing X509 Extensions
1313
*/
14-
public class X509ExtentionParsingUtil {
14+
public class X509ExtensionParsingUtil {
1515
public static DEROctetString extractExtensionValue(X509Certificate cert, String Oid)
1616
throws CertificateParsingException {
1717
byte[] extensionValue = cert.getExtensionValue(Oid);
1818

1919
if (extensionValue == null || extensionValue.length == 0) {
20-
throw new CertificateParsingException("Did not find extension with OID " + Oid);
20+
// Did not find extension
21+
return null;
2122
}
2223

2324
ASN1Object asn1Object = getAsn1Object(extensionValue);

u2f-ref-code/java/src/com/google/u2f/server/impl/attestation/android/AndroidKeyStoreAttestation.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package com.google.u2f.server.impl.attestation.android;
22

3-
import com.google.u2f.server.impl.attestation.X509ExtentionParsingUtil;
3+
import com.google.u2f.server.impl.attestation.X509ExtensionParsingUtil;
44

55
import org.bouncycastle.asn1.ASN1Encodable;
66
import org.bouncycastle.asn1.ASN1Integer;
@@ -134,7 +134,11 @@ public static AndroidKeyStoreAttestation Parse(X509Certificate cert)
134134
throws CertificateParsingException {
135135
// Extract the extension from the certificate
136136
DEROctetString extensionValue =
137-
X509ExtentionParsingUtil.extractExtensionValue(cert, KEY_DESCRIPTION_OID);
137+
X509ExtensionParsingUtil.extractExtensionValue(cert, KEY_DESCRIPTION_OID);
138+
139+
if (extensionValue == null) {
140+
return null;
141+
}
138142

139143
// Get the KeyDescription sequence
140144
DLSequence keyDescriptionSequence = getKeyDescriptionSequence(extensionValue);
@@ -179,7 +183,7 @@ public byte[] getAttestationChallenge() {
179183
private static DLSequence getKeyDescriptionSequence(DEROctetString octet)
180184
throws CertificateParsingException {
181185
// Read out the Sequence
182-
ASN1Object asn1Object = X509ExtentionParsingUtil.getAsn1Object(octet.getOctets());
186+
ASN1Object asn1Object = X509ExtensionParsingUtil.getAsn1Object(octet.getOctets());
183187
if (asn1Object == null || !(asn1Object instanceof DLSequence)) {
184188
throw new CertificateParsingException("Expected KeyDescription Sequence.");
185189
}

u2f-ref-code/java/src/com/google/u2f/server/impl/attestation/u2f/U2fAttestation.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package com.google.u2f.server.impl.attestation.u2f;
22

33
import com.google.u2f.server.data.SecurityKeyData.Transports;
4-
import com.google.u2f.server.impl.attestation.X509ExtentionParsingUtil;
4+
import com.google.u2f.server.impl.attestation.X509ExtensionParsingUtil;
55

66
import org.bouncycastle.asn1.ASN1Object;
77
import org.bouncycastle.asn1.DERBitString;
@@ -54,10 +54,15 @@ public class U2fAttestation {
5454
*/
5555
public static U2fAttestation Parse(X509Certificate cert) throws CertificateParsingException {
5656
DEROctetString extValue =
57-
X509ExtentionParsingUtil.extractExtensionValue(cert, TRANSPORT_EXTENSION_OID);
57+
X509ExtensionParsingUtil.extractExtensionValue(cert, TRANSPORT_EXTENSION_OID);
58+
59+
if (extValue == null) {
60+
// No Transport extension was found
61+
return new U2fAttestation(null);
62+
}
5863

5964
// Read out the BitString
60-
ASN1Object asn1Object = X509ExtentionParsingUtil.getAsn1Object(extValue.getOctets());
65+
ASN1Object asn1Object = X509ExtensionParsingUtil.getAsn1Object(extValue.getOctets());
6166
if (asn1Object == null || !(asn1Object instanceof DERBitString)) {
6267
throw new CertificateParsingException("No BitString found in transports extension");
6368
}

u2f-ref-code/java/tests/com/google/u2f/server/impl/attestation/u2f/U2fAttestationTest.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ public void testValidCertOneTransport() throws Exception {
2525

2626
assertNotNull(attestation);
2727
List<Transports> transports = attestation.getTransports();
28+
assertNotNull(transports);
2829
assertEquals(1, transports.size());
2930
assertTrue(transports.contains(Transports.BLUETOOTH_BREDR));
3031
}
@@ -34,12 +35,11 @@ public void testMalformedCert() throws Exception {
3435
U2fAttestation.Parse(TRUSTED_CERTIFICATE_MALFORMED_TRANSPORTS_EXTENSION);
3536
}
3637

37-
// There is no Transports Extension in the attestation cert
38-
// and the current behavior is to throw (the ServerImplementation code catches).
39-
// TODO(aczeskis): change behavior of ServerImplementation and update test
40-
@Test(expected = CertificateParsingException.class)
38+
@Test
4139
public void testValidCertNoTransports() throws Exception {
42-
U2fAttestation.Parse(TRUSTED_CERTIFICATE_2);
40+
U2fAttestation attestation = U2fAttestation.Parse(TRUSTED_CERTIFICATE_2);
41+
assertNotNull(attestation);
42+
assertTrue(attestation.getTransports() == null);
4343
}
4444

4545
@Test
@@ -48,6 +48,7 @@ public void testValidCertMultipleTransports() throws Exception {
4848

4949
assertNotNull(attestation);
5050
List<Transports> transports = attestation.getTransports();
51+
assertNotNull(transports);
5152
assertEquals(3, transports.size());
5253
assertTrue(transports.contains(Transports.BLUETOOTH_BREDR));
5354
assertTrue(transports.contains(Transports.BLUETOOTH_LOW_ENERGY));

0 commit comments

Comments
 (0)