Ejemplo n.º 1
0
        /// <summary>
        /// Decodes attested credential data.
        /// </summary>
        public AttestedCredentialData(BinaryReader reader)
        {
            // First 16 bytes is AAGUID
            byte[] aaguidBytes = reader.ReadBytes(Marshal.SizeOf(typeof(Guid)));

            // GUID from authenticator is big endian. If we are on a little endian system, convert.
            this.AaGuid = aaguidBytes.ToGuidBigEndian();

            // Byte length of Credential ID, 16-bit unsigned big-endian integer.
            byte[] credentialIDLenBytes = reader.ReadBytes(sizeof(UInt16));

            // Credential ID length from authenticator is big endian.  If we are on little endian system, convert.
            ushort credentialIDLen = credentialIDLenBytes.ToUInt16BigEndian();

            // Read the credential ID bytes
            this.CredentialID = reader.ReadBytes(credentialIDLen);

            // "Determining attested credential data's length, which is variable, involves determining
            // credentialPublicKey's beginning location given the preceding credentialId's length, and
            // then determining the credentialPublicKey's length"

            // "CBORObject.Read: This method will read from the stream until the end
            // of the CBOR object is reached or an error occurs, whichever happens first."

            // Read the CBOR object from the stream
            var cpk = PeterO.Cbor.CBORObject.Read(reader.BaseStream);

            // Encode the CBOR object back to a byte array.
            this.CredentialPublicKey = new CredentialPublicKey(cpk);
        }
        /// <summary>
        /// Decodes attested credential data.
        /// </summary>
        public AttestedCredentialData(BinaryReader reader)
        {
            // First 16 bytes is AAGUID
            var aaguidBytes = reader.ReadBytes(Marshal.SizeOf(typeof(Guid)));

            if (BitConverter.IsLittleEndian)
            {
                // GUID from authenticator is big endian. If we are on a little endian system, convert.
                AaGuid = FromBigEndian(aaguidBytes);
            }
            else
            {
                AaGuid = new Guid(aaguidBytes);
            }

            // Byte length of Credential ID, 16-bit unsigned big-endian integer.
            var credentialIDLenBytes = reader.ReadBytes(sizeof(UInt16));

            if (BitConverter.IsLittleEndian)
            {
                // Credential ID length from authenticator is big endian.  If we are on little endian system, convert.
                Array.Reverse(credentialIDLenBytes);
            }

            // Convert the read bytes to uint16 so we know how many bytes to read for the credential ID
            var credentialIDLen = BitConverter.ToUInt16(credentialIDLenBytes, 0);

            // Read the credential ID bytes
            CredentialID = reader.ReadBytes(credentialIDLen);

            // "Determining attested credential data's length, which is variable, involves determining
            // credentialPublicKey's beginning location given the preceding credentialId's length, and
            // then determining the credentialPublicKey's length"

            // "CBORObject.Read: This method will read from the stream until the end
            // of the CBOR object is reached or an error occurs, whichever happens first."

            // Read the CBOR object from the stream
            var cpk = PeterO.Cbor.CBORObject.Read(reader.BaseStream);

            // Encode the CBOR object back to a byte array.
            CredentialPublicKey = new CredentialPublicKey(cpk);
        }