Exemple #1
0
        public override void ReadServer(TlsBuffer incoming)
        {
            curveType = (ECCurveType)incoming.ReadByte();

            //  Currently, we only support named curves
            if (curveType == ECCurveType.named_curve)
            {
                namedCurve = (NamedCurve)incoming.ReadInt16();

                // TODO Check namedCurve is one we offered?
                domainParameters = NamedCurveHelper.GetECParameters(namedCurve);
            }
            else
            {
                // TODO Add support for explicit curve parameters
                throw new TlsException(AlertDescription.HandshakeFailure, "Unsupported elliptic curve type `{0}'.", curveType);
            }

            var publicLength = incoming.ReadByte();

            publicBytes = incoming.ReadBytes(publicLength);

            // TODO Check RFC 4492 for validation
            serverQ = domainParameters.Curve.DecodePoint(publicBytes);

            Signature = Signature.Read(TlsProtocolCode.Tls12, incoming);
        }
Exemple #2
0
        public EllipticCurveKeyExchange(TlsContext context)
        {
            curveType        = ECCurveType.named_curve;
            namedCurve       = context.Configuration.UserSettings.NamedCurve ?? NamedCurve.secp256k1;
            domainParameters = NamedCurveHelper.GetECParameters(namedCurve);

            GenerateKeyPair(context, domainParameters, out serverQ, out serverD);
            publicBytes = ExternalizeKey(serverQ);

            Signature = new SignatureTls12(context.Session.ServerSignatureAlgorithm);
            using (var buffer = CreateParameterBuffer(context.HandshakeParameters))
                Signature.Create(buffer, context.Configuration.PrivateKey);
        }