public override bool Equals(Object obj) { if (this == obj) { return(true); } if (obj == null) { return(false); } if (GetType() != obj.GetType()) { return(false); } RawRegisterResponse other = (RawRegisterResponse)obj; if (!_attestationCertificate.Equals(other._attestationCertificate)) { return(false); } if (!Arrays.AreEqual(_keyHandle, other._keyHandle)) { return(false); } if (!Arrays.AreEqual(_signature, other._signature)) { return(false); } return(Arrays.AreEqual(_userPublicKey, other._userPublicKey)); }
public static RawRegisterResponse FromBase64(String rawDataBase64) { byte[] bytes = Utils.Base64StringToByteArray(rawDataBase64); Stream stream = new MemoryStream(bytes); var binaryReader = new BinaryReader(stream); byte reservedByte = binaryReader.ReadByte(); if (reservedByte != RegistrationReservedByteValue) { throw new U2fException(String.Format( "Incorrect value of reserved byte. Expected: {0}. Was: {1}", RegistrationReservedByteValue, reservedByte)); } try { byte[] publicKey = binaryReader.ReadBytes(65); byte[] keyHandle = binaryReader.ReadBytes(binaryReader.ReadByte()); X509CertificateParser x509CertificateParser = new X509CertificateParser(); var x509Certificate = x509CertificateParser.ReadCertificate(stream); var rawRegisterResponse = new RawRegisterResponse( publicKey, keyHandle, x509Certificate, Utils.ReadAllBytes(binaryReader) ); return(rawRegisterResponse); } catch (CertificateException e) { throw new U2fException("Error when parsing attestation certificate", e); } finally { stream.Dispose(); binaryReader.Dispose(); } }
public static RawRegisterResponse FromBase64(String rawDataBase64) { byte[] bytes = Utils.Base64StringToByteArray(rawDataBase64); Stream stream = new MemoryStream(bytes); BinaryReader binaryReader = new BinaryReader(stream); try { byte reservedByte = binaryReader.ReadByte(); if (reservedByte != RegistrationReservedByteValue) { throw new U2fException(String.Format("Incorrect value of reserved byte. Expected: {0}. Was: {1}", RegistrationReservedByteValue, reservedByte)); } byte[] publicKey = binaryReader.ReadBytes(65); byte[] keyHandle = binaryReader.ReadBytes(binaryReader.ReadByte()); X509CertificateParser x509CertificateParser = new X509CertificateParser(); X509Certificate attestationCertificate = x509CertificateParser.ReadCertificate(stream); int size = (int)(binaryReader.BaseStream.Length - binaryReader.BaseStream.Position); byte[] signature = binaryReader.ReadBytes(size); RawRegisterResponse rawRegisterResponse = new RawRegisterResponse( publicKey, keyHandle, attestationCertificate, signature); return rawRegisterResponse; } catch (CertificateException e) { throw new U2fException("Error when parsing attestation certificate", e); } finally { stream.Dispose(); binaryReader.Dispose(); } }
private void CreateResponses() { _registerResponse = new RegisterResponse(TestConts.REGISTRATION_RESPONSE_DATA_BASE64, TestConts.CLIENT_DATA_REGISTER_BASE64); _rawAuthenticateResponse = RawRegisterResponse.FromBase64(_registerResponse.RegistrationData); _deviceRegistration = _rawAuthenticateResponse.CreateDevice(); _authenticateResponse = new AuthenticateResponse(TestConts.CLIENT_DATA_AUTHENTICATE_BASE64, TestConts.SIGN_RESPONSE_DATA_BASE64, TestConts.KEY_HANDLE_BASE64); }