示例#1
0
            public void GetCwtKey(CwtPublicKey rpk)
            {
                try {
                    Cwt cwt = Cwt.Decode(rpk.EncodedCwt(), CwtTrustKeySet, CwtTrustKeySet);

                    AsymmetricKeyParameter pub = cwt.Cnf.Key.AsPublicKey();
                    SubjectPublicKeyInfo   spi = SubjectPublicKeyInfoFactory.CreateSubjectPublicKeyInfo(pub);
                    rpk.SetSubjectPublicKeyInfo(spi);

                    AuthenticationKey = cwt.Cnf.Key;
                    return;
                }
                catch {
                }

                TlsEvent ev = new TlsEvent(TlsEvent.EventCode.ServerCertificate)
                {
                    Certificate = rpk
                };

                EventHandler <TlsEvent> handler = TlsEventHandler;

                if (handler != null)
                {
                    handler(this, ev);
                }

                if (!ev.Processed)
                {
                    throw new TlsFatalAlert(AlertDescription.certificate_unknown);
                }

                AuthenticationKey = ev.KeyValue;
            }
示例#2
0
            public void GetCwtKey(CwtPublicKey rpk)
            {
                Cwt cwt;

                try {
                    cwt = Cwt.Decode(rpk.EncodedCwt(), CwtTrustRoots, CwtTrustRoots);

                    AuthenticationKey = cwt.Cnf.CoseKey;
                }
                catch (Exception e)
                {
                    TlsEvent ev = new TlsEvent(TlsEvent.EventCode.ClientCertificate)
                    {
                        Certificate = rpk
                    };

                    EventHandler <TlsEvent> handler = TlsEventHandler;
                    if (handler != null)
                    {
                        handler(this, ev);
                    }

                    if (!ev.Processed)
                    {
                        throw new TlsFatalAlert(AlertDescription.certificate_unknown);
                    }

                    AuthenticationKey = ev.KeyValue;
                }
            }
示例#3
0
        public override AbstractCertificate ParseServerCertificate(short certificateType, Stream io)
        {
            switch (certificateType)
            {
            case CertificateType.CwtPublicKey:
                try {
                    CwtPublicKey cwtPub = CwtPublicKey.Parse(io);

                    Cwt cwtServer = Cwt.Decode(cwtPub.EncodedCwt(), CwtTrustKeySet, CwtTrustKeySet);

                    AsymmetricKeyParameter pubKey = cwtServer.Cnf.Key.AsPublicKey();

                    SubjectPublicKeyInfo spi = SubjectPublicKeyInfoFactory.CreateSubjectPublicKeyInfo(pubKey);
                    cwtPub.SetSubjectPublicKeyInfo(spi);

                    return(cwtPub);
                }
                catch {
                    return(null);
                }

            default:
                return(null);
            }
        }
示例#4
0
 public TlsKeyPair(Cwt publicKey, OneKey privateKey)
 {
     this.PrivateKey = privateKey;
     this.PublicCwt  = publicKey;
     CertType        = CertificateType.CwtPublicKey; // CWT
 }