1- package com .google .u2f .server .impl .androidattestation ;
1+ package com .google .u2f .server .impl .attestation .android ;
2+
3+ import com .google .u2f .server .impl .attestation .X509ExtentionParsingUtil ;
24
35import org .bouncycastle .asn1 .ASN1Encodable ;
4- import org .bouncycastle .asn1 .ASN1InputStream ;
56import org .bouncycastle .asn1 .ASN1Integer ;
67import org .bouncycastle .asn1 .ASN1Object ;
78import org .bouncycastle .asn1 .ASN1Primitive ;
8- import org .bouncycastle .asn1 .ASN1Sequence ;
99import org .bouncycastle .asn1 .DEROctetString ;
1010import org .bouncycastle .asn1 .DERSet ;
1111import org .bouncycastle .asn1 .DERTaggedObject ;
1212import org .bouncycastle .asn1 .DLSequence ;
1313
14- import java .io .IOException ;
1514import java .math .BigInteger ;
1615import java .security .cert .CertificateParsingException ;
1716import java .security .cert .X509Certificate ;
@@ -136,7 +135,8 @@ private AndroidKeyStoreAttestation(Integer keymasterVersion, byte[] attestationC
136135 public static AndroidKeyStoreAttestation Parse (X509Certificate cert )
137136 throws CertificateParsingException {
138137 // Extract the extension from the certificate
139- byte [] extensionValue = extractExtensionValue (cert );
138+ DEROctetString extensionValue =
139+ X509ExtentionParsingUtil .extractExtensionValue (cert , KEY_DESCRIPTION_OID );
140140
141141 // Get the KeyDescription sequence
142142 DLSequence keyDescriptionSequence = getKeyDescriptionSequence (extensionValue );
@@ -151,8 +151,8 @@ public static AndroidKeyStoreAttestation Parse(X509Certificate cert)
151151 DLSequence softwareEnforcedSequence = getSoftwareEncodedSequence (keyDescriptionSequence );
152152 AuthorizationList softwareAuthorizationList =
153153 extractAuthorizationList (softwareEnforcedSequence );
154-
155- // TODO(aczeskis) Extract the tee authorization list
154+
155+ // TODO(aczeskis) Extract the TEE authorization list
156156
157157 return new AndroidKeyStoreAttestation (keymasterVersion , challenge , softwareAuthorizationList );
158158 }
@@ -178,43 +178,10 @@ public byte[] getAttestationChallenge() {
178178 return attestationChallenge ;
179179 }
180180
181- private static byte [] extractExtensionValue (X509Certificate cert )
182- throws CertificateParsingException {
183- byte [] extensionValue = cert .getExtensionValue (KEY_DESCRIPTION_OID );
184-
185- if (extensionValue == null || extensionValue .length == 0 ) {
186- throw new CertificateParsingException (
187- "Did not find KeyDescription extension with OID " + KEY_DESCRIPTION_OID );
188- }
189-
190- return extensionValue ;
191- }
192-
193- private static DLSequence getKeyDescriptionSequence (byte [] extensionValue )
181+ private static DLSequence getKeyDescriptionSequence (DEROctetString octet )
194182 throws CertificateParsingException {
195- ASN1InputStream ais = new ASN1InputStream (extensionValue );
196- ASN1Object asn1Object ;
197-
198- // Read the key description octet string
199- try {
200- asn1Object = ais .readObject ();
201- ais .close ();
202- } catch (IOException e ) {
203- throw new CertificateParsingException ("Not able to read KeyDescription ASN.1 object" , e );
204- }
205- if (asn1Object == null || !(asn1Object instanceof DEROctetString )) {
206- throw new CertificateParsingException ("Expected KeyDescription Octet String." );
207- }
208- DEROctetString octet = (DEROctetString ) asn1Object ;
209-
210183 // Read out the Sequence
211- ais = new ASN1InputStream (octet .getOctets ());
212- try {
213- asn1Object = ais .readObject ();
214- ais .close ();
215- } catch (IOException e ) {
216- throw new CertificateParsingException ("Not able to read KeyDescription Octet String." , e );
217- }
184+ ASN1Object asn1Object = X509ExtentionParsingUtil .getAsn1Object (octet .getOctets ());
218185 if (asn1Object == null || !(asn1Object instanceof DLSequence )) {
219186 throw new CertificateParsingException ("Expected KeyDescription Sequence." );
220187 }
0 commit comments