예제 #1
0
        public bool Decode(byte[] authData)
        {
            try {
                int index = 0;

                // rpIdHash	(32)
                RpIdHash = authData.Skip(index).Take(32).ToArray();
                index    = index + 32;

                // flags(1)
                {
                    byte flags = authData[index];
                    index++;
                    Flags_UserPresentResult              = Common.GetBit(flags, 0);
                    Flags_UserVerifiedResult             = Common.GetBit(flags, 2);
                    Flags_AttestedCredentialDataIncluded = Common.GetBit(flags, 6);
                    Flags_ExtensionDataIncluded          = Common.GetBit(flags, 7);
                }

                // signCount(4)
                {
                    SignCount = Common.ToInt32(authData, index, true);
                    index     = index + 4;
                }

                // aaguid	16
                Aaguid = authData.Skip(index).Take(16).ToArray();
                index  = index + 16;

                // credentialId
                {
                    int credentialIdLength = Common.ToInt16(authData, index, true);
                    index = index + 2;

                    CredentialId = authData.Skip(index).Take(credentialIdLength).ToArray();
                    index        = index + credentialIdLength;
                }

                // credentialPublicKey
                {
                    var tmp = authData.Skip(index).ToArray();

                    // tmp -> cbors
                    //          [0] credentialPublicKey
                    //          [1] extensions
                    var cbors = CBORObject.DecodeSequenceFromBytes(tmp, CBOREncodeOptions.Default);
                    if (cbors.Count() > 0)
                    {
                        var credentialPublicKeyByte = cbors[0].EncodeToBytes();
                        // PublickKeyをPEMに変換する
                        PublicKeyPem = this.convertCOSEtoPEM(credentialPublicKeyByte);
                    }
                }

                return(true);
            } catch (Exception ex) {
                Logger.Err(ex, "Decode");
                return(false);
            }
        }
예제 #2
0
        private void parseAuthData(byte[] data)
        {
            try {
                int index = 0;

                // rpIdHash	(32)
                Attestation.RpIdHash = data.Skip(index).Take(32).ToArray();
                index = index + 32;

                // flags(1)
                {
                    byte flags = data[index];
                    index++;
                    Attestation.Flags_UserPresentResult              = Common.GetBit(flags, 0);
                    Attestation.Flags_UserVerifiedResult             = Common.GetBit(flags, 2);
                    Attestation.Flags_AttestedCredentialDataIncluded = Common.GetBit(flags, 6);
                    Attestation.Flags_ExtensionDataIncluded          = Common.GetBit(flags, 7);
                }

                // signCount(4)
                {
                    Attestation.SignCount = Common.ToInt32(data, index, true);
                    index = index + 4;
                }

                // aaguid	16
                Attestation.Aaguid = data.Skip(index).Take(16).ToArray();
                index = index + 16;

                // credentialId
                {
                    int credentialIdLength = Common.ToInt16(data, index, true);
                    index = index + 2;

                    Attestation.CredentialId = data.Skip(index).Take(credentialIdLength).ToArray();
                    index = index + credentialIdLength;
                }

                // credentialPublicKey
                if (Attestation.Flags_AttestedCredentialDataIncluded)
                {
                    // credentialPublicKey(cbor) & extensions(cbor)
                    var tmp = data.Skip(index).ToArray();

                    // var tmp = Attestation.CredentialPublicKeyByte.ToArray();
                    //var tmp = Common.HexStringToBytes("A30181684649444F5F325F3003504B44444978AA4DB5A3221C6F9A4E5CDB04A362726BF5627570F5627576F5");
                    //var concatenated = Attestation.CredentialPublicKeyByte.Concat(tmp).ToArray();

                    // tmp -> cbors
                    //          [0] credentialPublicKey
                    //          [1] extensions
                    var cbors = CBORObject.DecodeSequenceFromBytes(tmp, CBOREncodeOptions.Default);
                    if (cbors.Count() > 0)
                    {
                        Attestation.CredentialPublicKey = cbors[0].ToJSONString();
                        Logger.Log("credentialPublicKeyCobr:" + Attestation.CredentialPublicKey);

                        Attestation.CredentialPublicKeyByte = cbors[0].EncodeToBytes();
                    }
                }
            } catch (Exception ex) {
                Logger.Err(ex, "parseAuthData");
            }
            Attestation.AuthData = data.ToArray();
        }