|
30 | 30 | import com.yubico.webauthn.data.AuthenticatorAssertionResponse;
|
31 | 31 | import com.yubico.webauthn.data.AuthenticatorData;
|
32 | 32 | import com.yubico.webauthn.data.ByteArray;
|
| 33 | +import com.yubico.webauthn.data.COSEAlgorithmIdentifier; |
33 | 34 | import com.yubico.webauthn.data.PublicKeyCredentialDescriptor;
|
34 | 35 | import com.yubico.webauthn.data.UserIdentity;
|
35 | 36 | import lombok.Builder;
|
@@ -143,12 +144,85 @@ public class Step3 {
|
143 | 144 | * {@link RegisteredCredentialBuilder#publicKeyCose(ByteArray) publicKeyCose} is a required
|
144 | 145 | * parameter.
|
145 | 146 | *
|
| 147 | + * <p>Alternatively, the public key can be specified using the {@link |
| 148 | + * #publicKeyEs256Raw(ByteArray)} method if the key is stored in the U2F format (<code> |
| 149 | + * ALG_KEY_ECC_X962_RAW</code> as specified in <a |
| 150 | + * href="https://fidoalliance.org/specs/fido-v2.0-id-20180227/fido-registry-v2.0-id-20180227.html#public-key-representation-formats">FIDO |
| 151 | + * Registry §3.6.2 Public Key Representation Formats</a>). This is mostly useful for public |
| 152 | + * keys registered via the U2F JavaScript API. |
| 153 | + * |
| 154 | + * @see #publicKeyEs256Raw(ByteArray) |
146 | 155 | * @see RegisteredCredentialBuilder#publicKeyCose(ByteArray)
|
| 156 | + * @see <a |
| 157 | + * href="https://fidoalliance.org/specs/fido-v2.0-id-20180227/fido-registry-v2.0-id-20180227.html#public-key-representation-formats">FIDO |
| 158 | + * Registry §3.6.2 Public Key Representation Formats</a> |
147 | 159 | */
|
148 | 160 | public RegisteredCredentialBuilder publicKeyCose(ByteArray publicKeyCose) {
|
149 | 161 | return builder.publicKeyCose(publicKeyCose);
|
150 | 162 | }
|
| 163 | + |
| 164 | + /** |
| 165 | + * Specify the credential public key in U2F format. |
| 166 | + * |
| 167 | + * <p>An alternative to {@link #publicKeyCose(ByteArray)}, this method expects an {@link |
| 168 | + * COSEAlgorithmIdentifier#ES256 ES256} public key in <code>ALG_KEY_ECC_X962_RAW</code> |
| 169 | + * format as specified in <a |
| 170 | + * href="https://fidoalliance.org/specs/fido-v2.0-id-20180227/fido-registry-v2.0-id-20180227.html#public-key-representation-formats">FIDO |
| 171 | + * Registry §3.6.2 Public Key Representation Formats</a>. |
| 172 | + * |
| 173 | + * <p>This is primarily intended for public keys registered via the U2F JavaScript API. If |
| 174 | + * your application has only used the <code>navigator.credentials.create()</code> API to |
| 175 | + * register credentials, you should use {@link #publicKeyCose(ByteArray)} instead. |
| 176 | + * |
| 177 | + * @see RegisteredCredentialBuilder#publicKeyCose(ByteArray) |
| 178 | + */ |
| 179 | + public RegisteredCredentialBuilder publicKeyEs256Raw(ByteArray publicKeyEs256Raw) { |
| 180 | + return builder.publicKeyCose(WebAuthnCodecs.rawEcKeyToCose(publicKeyEs256Raw)); |
| 181 | + } |
151 | 182 | }
|
152 | 183 | }
|
| 184 | + |
| 185 | + /** |
| 186 | + * The credential public key encoded in COSE_Key format, as defined in Section 7 of <a |
| 187 | + * href="https://tools.ietf.org/html/rfc8152">RFC 8152</a>. This method overwrites {@link |
| 188 | + * #publicKeyEs256Raw(ByteArray)}. |
| 189 | + * |
| 190 | + * <p>This is used to verify the {@link AuthenticatorAssertionResponse#getSignature() signature} |
| 191 | + * in authentication assertions. |
| 192 | + * |
| 193 | + * <p>Alternatively, the public key can be specified using the {@link |
| 194 | + * #publicKeyEs256Raw(ByteArray)} method if the key is stored in the U2F format (<code> |
| 195 | + * ALG_KEY_ECC_X962_RAW</code> as specified in <a |
| 196 | + * href="https://fidoalliance.org/specs/fido-v2.0-id-20180227/fido-registry-v2.0-id-20180227.html#public-key-representation-formats">FIDO |
| 197 | + * Registry §3.6.2 Public Key Representation Formats</a>). This is mostly useful for public keys |
| 198 | + * registered via the U2F JavaScript API. |
| 199 | + * |
| 200 | + * @see AttestedCredentialData#getCredentialPublicKey() |
| 201 | + * @see RegistrationResult#getPublicKeyCose() |
| 202 | + */ |
| 203 | + public RegisteredCredentialBuilder publicKeyCose(@NonNull ByteArray publicKeyCose) { |
| 204 | + this.publicKeyCose = publicKeyCose; |
| 205 | + return this; |
| 206 | + } |
| 207 | + |
| 208 | + /** |
| 209 | + * Specify the credential public key in U2F format. This method overwrites {@link |
| 210 | + * #publicKeyCose(ByteArray)}. |
| 211 | + * |
| 212 | + * <p>An alternative to {@link #publicKeyCose(ByteArray)}, this method expects an {@link |
| 213 | + * COSEAlgorithmIdentifier#ES256 ES256} public key in <code>ALG_KEY_ECC_X962_RAW</code> format |
| 214 | + * as specified in <a |
| 215 | + * href="https://fidoalliance.org/specs/fido-v2.0-id-20180227/fido-registry-v2.0-id-20180227.html#public-key-representation-formats">FIDO |
| 216 | + * Registry §3.6.2 Public Key Representation Formats</a>. |
| 217 | + * |
| 218 | + * <p>This is primarily intended for public keys registered via the U2F JavaScript API. If your |
| 219 | + * application has only used the <code>navigator.credentials.create()</code> API to register |
| 220 | + * credentials, you should use {@link #publicKeyCose(ByteArray)} instead. |
| 221 | + * |
| 222 | + * @see RegisteredCredentialBuilder#publicKeyCose(ByteArray) |
| 223 | + */ |
| 224 | + public RegisteredCredentialBuilder publicKeyEs256Raw(ByteArray publicKeyEs256Raw) { |
| 225 | + return publicKeyCose(WebAuthnCodecs.rawEcKeyToCose(publicKeyEs256Raw)); |
| 226 | + } |
153 | 227 | }
|
154 | 228 | }
|
0 commit comments