Example #1
0
        public override bool Equals(object obj)
        {
            if (!(obj is RawRegisterResponse))
            {
                return(false);
            }
            if (this == obj)
            {
                return(true);
            }
            if (GetType() != obj.GetType())
            {
                return(false);
            }
            RawRegisterResponse other = (RawRegisterResponse)obj;

            if (!_attestationCertificate.Equals(other._attestationCertificate))
            {
                return(false);
            }
            if (!_keyHandle.SequenceEqual(other._keyHandle))
            {
                return(false);
            }
            if (!_signature.SequenceEqual(other._signature))
            {
                return(false);
            }
            return(_userPublicKey.SequenceEqual(other._userPublicKey));
        }
Example #2
0
        public static DeviceRegistration FinishRegistration(StartedRegistration startedRegistration, RegisterResponse tokenResponse, HashSet <string> facets = null)
        {
            ClientData clientData = tokenResponse.GetClientData();

            clientData.CheckContent(RegisterType, startedRegistration.Challenge, facets);

            RawRegisterResponse rawRegisterResponse = RawRegisterResponse.FromBase64(tokenResponse.RegistrationData);

            rawRegisterResponse.CheckSignature(startedRegistration.AppId, clientData.AsJson());

            return(rawRegisterResponse.CreateDevice());
        }
Example #3
0
        public static RawRegisterResponse FromBase64(string rawDataBase64)
        {
            if (string.IsNullOrWhiteSpace(rawDataBase64))
            {
                return(null);
            }
            else
            {
                byte[] bytes = rawDataBase64.Base64StringToByteArray();

                Stream       stream       = new MemoryStream(bytes);
                BinaryReader binaryReader = new BinaryReader(stream);

                try
                {
                    byte reservedByte = binaryReader.ReadByte();
                    if (reservedByte != RegistrationReservedByteValue)
                    {
                        return(null);
                    }

                    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 (Exception ex)
                {
                    throw ex;
                }
                finally
                {
                    stream.Dispose();
                    binaryReader.Dispose();
                }
            }
        }