Пример #1
0
 public KeyGenThread(KeyGenForm p, PublicKeyAlgorithm a, Int32 b)
 {
     this._parent    = p;
     this._algorithm = a;
     this._bits      = b;
     this._rnd       = new KeyGenRandomGenerator();
 }
Пример #2
0
        public override bool Commit(ContainerOptions options)
        {
            //�Í��A���S���Y��������options�𒼐ڂ������Ă���̂ł����ł͉�����Ȃ��Ă悢
            try {
                PublicKeyAlgorithm[] pa = new PublicKeyAlgorithm[2];
                if(_hostKeyBox.SelectedIndex==0) {
                    pa[0] = PublicKeyAlgorithm.DSA;
                    pa[1] = PublicKeyAlgorithm.RSA;
                }
                else {
                    pa[0] = PublicKeyAlgorithm.RSA;
                    pa[1] = PublicKeyAlgorithm.DSA;
                }
                options.HostKeyAlgorithmOrder = LocalSSHUtil.FormatPublicKeyAlgorithmList(pa);

                try {
                    options.SSHWindowSize = Int32.Parse(_windowSizeBox.Text);
                }
                catch(FormatException) {
                    GUtil.Warning(this, GApp.Strings.GetString("Message.OptionDialog.InvalidWindowSize"));
                    return false;
                }

                options.RetainsPassphrase = _retainsPassphrase.Checked;
                options.SSHCheckMAC = _sshCheckMAC.Checked;
                options.CipherAlgorithmOrder = _cipherAlgorithmOrder;

                return true;
            }
            catch(Exception ex) {
                GUtil.Warning(this, ex.Message);
                return false;
            }
        }
Пример #3
0
 public static string[] FormatPublicKeyAlgorithmList(PublicKeyAlgorithm[] value) {
     string[] ret = new string[value.Length];
     int i = 0;
     foreach (PublicKeyAlgorithm a in value)
         ret[i++] = a.ToString();
     return ret;
 }
Пример #4
0
 public static int GetSecretMPICount(PublicKeyAlgorithm pkAlgorithm)
 {
     if (pkAlgorithm.Equals(PublicKeyAlgorithm.DSA)) return Constants.DSA_SECRET_KEY_MPI_COUNT;
     else if (pkAlgorithm.Equals(PublicKeyAlgorithm.ElGamalEncryptOnly)) return Constants.ELGAMAL_ENCRYPT_ONLY_SECRET_KEY_MPI_COUNT;
     else if (pkAlgorithm.Equals(PublicKeyAlgorithm.RSA)) return Constants.RSA_SECRET_KEY_MPI_COUNT;
     else return 0;
 }
Пример #5
0
 public KeyGenThread(KeyGenWizard p, PublicKeyAlgorithm a, int b)
 {
     _parent    = p;
     _algorithm = a;
     _bitCount  = b;
     _rnd       = new KeyGenRandomGenerator();
 }
Пример #6
0
        private bool CommitSSHOptions()
        {
            //暗号アルゴリズム順序は_optionsを直接いじっているのでここでは何もしなくてよい
            try {
                PublicKeyAlgorithm[] pa = new PublicKeyAlgorithm[2];
                if (_hostKeyBox.SelectedIndex == 0)
                {
                    pa[0] = PublicKeyAlgorithm.DSA;
                    pa[1] = PublicKeyAlgorithm.RSA;
                }
                else
                {
                    pa[0] = PublicKeyAlgorithm.RSA;
                    pa[1] = PublicKeyAlgorithm.DSA;
                }
                _options.HostKeyAlgorithmOrder = SSHUtil.FormatPublicKeyAlgorithmList(pa);

                try {
                    _options.SSHWindowSize = Int32.Parse(_windowSizeBox.Text);
                }
                catch (FormatException) {
                    Util.Warning(this, Env.Strings.GetString("Message.OptionDialog.InvalidWindowSize"));
                    return(false);
                }

                _options.RetainsPassphrase = _retainsPassphrase.Checked;
                _options.SSHCheckMAC       = _sshCheckMAC.Checked;

                return(true);
            }
            catch (Exception ex) {
                Util.Warning(this, ex.Message);
                return(false);
            }
        }
Пример #7
0
 public KeyGenThread(KeyGenForm p, PublicKeyAlgorithm a, Int32 b)
 {
     this._parent = p;
     this._algorithm = a;
     this._bits = b;
     this._rnd = new KeyGenRandomGenerator();
 }
Пример #8
0
 public KeyGenThread(KeyGenWizard p, PublicKeyAlgorithm a, int b)
 {
     _parent = p;
     _algorithm = a;
     _bitCount = b;
     _rnd = new KeyGenRandomGenerator();
 }
Пример #9
0
        public static bool TryParsePublicKeyAlgorithm(this string text, ref PublicKeyAlgorithm algo)
        {
            switch (text)
            {
            case PublicKeyAlgorithmExt.ALGORITHM_RSA_KEY:
                algo = PublicKeyAlgorithm.SSH_RSA;
                return(true);

            case PublicKeyAlgorithmExt.ALGORITHM_DSA_KEY:
                algo = PublicKeyAlgorithm.SSH_DSS;
                return(true);

            case PublicKeyAlgorithmExt.ALGORITHM_ECDSA_SHA2_NISTP256_KEY:
                algo = PublicKeyAlgorithm.ECDSA_SHA2_NISTP256;
                return(true);

            case PublicKeyAlgorithmExt.ALGORITHM_ECDSA_SHA2_NISTP384_KEY:
                algo = PublicKeyAlgorithm.ECDSA_SHA2_NISTP384;
                return(true);

            case PublicKeyAlgorithmExt.ALGORITHM_ECDSA_SHA2_NISTP521_KEY:
                algo = PublicKeyAlgorithm.ECDSA_SHA2_NISTP521;
                return(true);

            case PublicKeyAlgorithmExt.ALGORITHM_ED25519:
                algo = PublicKeyAlgorithm.ED25519;
                return(true);

            default:
                return(false);
            }
        }
Пример #10
0
        PublicKeyAlgorithmTag GetPublicKeyAlgorithmTag(PublicKeyAlgorithm algorithm)
        {
            switch (algorithm)
            {
            case PublicKeyAlgorithm.DiffieHellman: return(PublicKeyAlgorithmTag.DiffieHellman);

            case PublicKeyAlgorithm.Dsa: return(PublicKeyAlgorithmTag.Dsa);

            case PublicKeyAlgorithm.EdwardsCurveDsa: throw new NotSupportedException("EDDSA is not currently supported.");

            case PublicKeyAlgorithm.ElGamalEncrypt: return(PublicKeyAlgorithmTag.ElGamalEncrypt);

            case PublicKeyAlgorithm.ElGamalGeneral: return(PublicKeyAlgorithmTag.ElGamalGeneral);

            case PublicKeyAlgorithm.EllipticCurve: return(PublicKeyAlgorithmTag.ECDH);

            case PublicKeyAlgorithm.EllipticCurveDsa: return(PublicKeyAlgorithmTag.ECDsa);

            case PublicKeyAlgorithm.RsaEncrypt: return(PublicKeyAlgorithmTag.RsaEncrypt);

            case PublicKeyAlgorithm.RsaGeneral: return(PublicKeyAlgorithmTag.RsaGeneral);

            case PublicKeyAlgorithm.RsaSign: return(PublicKeyAlgorithmTag.RsaSign);

            default: throw new ArgumentOutOfRangeException(nameof(algorithm));
            }
        }
Пример #11
0
        public static ISigner GetSigner(this PublicKeyAlgorithm aPublicKeyAlgorithm)
        {
            switch (aPublicKeyAlgorithm)
            {
            case PublicKeyAlgorithm.SSH_RSA:
            case PublicKeyAlgorithm.SSH_RSA_CERT_V1:
                return(SignerUtilities.GetSigner(PkcsObjectIdentifiers.Sha1WithRsaEncryption.Id));

            case PublicKeyAlgorithm.SSH_DSS:
            case PublicKeyAlgorithm.SSH_DSS_CERT_V1:
                return(SignerUtilities.GetSigner(X9ObjectIdentifiers.IdDsaWithSha1.Id));

            case PublicKeyAlgorithm.ECDSA_SHA2_NISTP256:
            case PublicKeyAlgorithm.ECDSA_SHA2_NISTP256_CERT_V1:
                return(SignerUtilities.GetSigner(X9ObjectIdentifiers.ECDsaWithSha256.Id));

            case PublicKeyAlgorithm.ECDSA_SHA2_NISTP384:
            case PublicKeyAlgorithm.ECDSA_SHA2_NISTP384_CERT_V1:
                return(SignerUtilities.GetSigner(X9ObjectIdentifiers.ECDsaWithSha384.Id));

            case PublicKeyAlgorithm.ECDSA_SHA2_NISTP521:
            case PublicKeyAlgorithm.ECDSA_SHA2_NISTP521_CERT_V1:
                return(SignerUtilities.GetSigner(X9ObjectIdentifiers.ECDsaWithSha512.Id));

            case PublicKeyAlgorithm.ED25519:
            case PublicKeyAlgorithm.ED25519_CERT_V1:
                return(new Ed25519Signer());

            default:
                Debug.Fail("Unknown algorithm");
                throw new Exception("Unknown algorithm");
            }
        }
Пример #12
0
        public override sealed string ToString()
        {
            StringBuilder bb = new StringBuilder();

            bb.Append("Version: ");
            bb.AppendLine(Version.ToString());
            bb.Append("SerialNumber: ");
            bb.AppendLine(SerialNumber.ToString());
            bb.Append("Signature: ");
            bb.Append(SignatureAlgorithm.ToString());
            bb.Append(", OID = ");
            bb.Append(HashAlgorithmConverter.GetString(SignatureAlgorithm));
            bb.Append("\n");
            bb.Append("Issuer: ");
            bb.Append(Issuer);
            bb.Append("\n");
            bb.Append("Validity: [From: ");
            bb.Append(ValidFrom.ToUniversalTime().ToString());
            bb.Append(" GMT To: ");
            bb.Append(ValidTo.ToUniversalTime().ToString());
            bb.Append(" GMT]\n");
            bb.Append("Subject: ");
            bb.Append(Subject);
            bb.Append("\n");
            bb.Append("Public Key Algorithm: ");
            bb.Append(PublicKeyAlgorithm.ToString());
            bb.Append("\n");
            bb.Append("Key: ");
            bb.Append(PublicKey.ToHex());
            bb.Append("\n");
            if (PublicKey.Scheme == Ecdsa.Enums.Ecc.P256)
            {
                bb.Append("ASN1 OID: prime256v1\n");
                bb.Append("NIST CURVE: P-256");
            }
            else if (PublicKey.Scheme == Ecdsa.Enums.Ecc.P384)
            {
                bb.Append("ASN1 OID: prime384v1\n");
                bb.Append("\n");
                bb.Append("NIST CURVE: P-384");
            }
            bb.Append("\n");
            bb.Append("Basic constraints: ");
            bb.Append(BasicConstraints);
            bb.Append("\n");
            bb.Append("SubjectKeyIdentifier: ");
            bb.Append(GXCommon.ToHex(SubjectKeyIdentifier, true));
            bb.Append("\n");
            bb.Append("KeyUsage: ");
            bb.Append(KeyUsage);
            bb.Append("\n");
            bb.Append("Signature Algorithm: ");
            bb.Append(SignatureAlgorithm.ToString());
            bb.Append("\n");
            bb.Append("Signature: ");
            bb.Append(GXCommon.ToHex(Signature, false));
            bb.Append("\n");
            return(bb.ToString());
        }
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="identity">Email of key pair owner</param>
        /// <param name="passphrase">Passphrase of key pair</param>
        /// <param name="publicKeyAlgorithm">PublicKeyAlgorithm.DSA_ELGAMAL or PublicKeyAlgorithm.RSA</param>
        /// <param name="publicKeyLength">PublicKeyLength.BITS_1024, PublicKeyLength.BITS_2048, PublicKeyLength.BITS_3072,,</param>
        public PgpKeyPairGenerator(string identity, char[] passphrase, PublicKeyAlgorithm publicKeyAlgorithm, PublicKeyLength publicKeyLength)
        {
            this.identity   = identity ?? throw new ArgumentNullException("identity can not be null!");
            this.passphrase = passphrase ?? throw new ArgumentNullException("passphrase can not be null!");

            this.publicKeyAlgorithm = publicKeyAlgorithm;
            this.publicKeyLength    = publicKeyLength;
        }
Пример #14
0
 public static PublicKeyAlgorithm[] ParsePublicKeyAlgorithm(string[] t) {
     PublicKeyAlgorithm[] ret = new PublicKeyAlgorithm[t.Length];
     int i = 0;
     foreach (string a in t) {
         ret[i++] = ParsePublicKeyAlgorithm(a);
     }
     return ret;
 }
 /// <summary>
 /// Two DnsResourceDataHostIdentityProtocol are equal iff their host identity tag, public key algorithm, public key and rendezvous servers fields
 /// are equal.
 /// </summary>
 public bool Equals(DnsResourceDataHostIdentityProtocol other)
 {
     return(other != null &&
            HostIdentityTag.Equals(other.HostIdentityTag) &&
            PublicKeyAlgorithm.Equals(other.PublicKeyAlgorithm) &&
            PublicKey.Equals(other.PublicKey) &&
            RendezvousServers.SequenceEqual(RendezvousServers));
 }
Пример #16
0
        static bool TryParsePublicKeyAlgorithm(string text, out PublicKeyAlgorithm algo)
        {
            switch (text)
            {
            case PublicKeyAlgorithmExt.ALGORITHM_RSA_KEY:
                algo = PublicKeyAlgorithm.SSH_RSA;
                break;

            case PublicKeyAlgorithmExt.ALGORITHM_RSA_CERT_V1:
                algo = PublicKeyAlgorithm.SSH_RSA_CERT_V1;
                break;

            case PublicKeyAlgorithmExt.ALGORITHM_DSA_KEY:
                algo = PublicKeyAlgorithm.SSH_DSS;
                break;

            case PublicKeyAlgorithmExt.ALGORITHM_DSA_CERT_V1:
                algo = PublicKeyAlgorithm.SSH_DSS_CERT_V1;
                break;

            case PublicKeyAlgorithmExt.ALGORITHM_ECDSA_SHA2_NISTP256_KEY:
                algo = PublicKeyAlgorithm.ECDSA_SHA2_NISTP256;
                break;

            case PublicKeyAlgorithmExt.ALGORITHM_ECDSA_SHA2_NISTP256_CERT_V1:
                algo = PublicKeyAlgorithm.ECDSA_SHA2_NISTP256_CERT_V1;
                break;

            case PublicKeyAlgorithmExt.ALGORITHM_ECDSA_SHA2_NISTP384_CERT_V1:
                algo = PublicKeyAlgorithm.ECDSA_SHA2_NISTP384_CERT_V1;
                break;

            case PublicKeyAlgorithmExt.ALGORITHM_ECDSA_SHA2_NISTP521_KEY:
                algo = PublicKeyAlgorithm.ECDSA_SHA2_NISTP521;
                break;

            case PublicKeyAlgorithmExt.ALGORITHM_ECDSA_SHA2_NISTP521_CERT_V1:
                algo = PublicKeyAlgorithm.ECDSA_SHA2_NISTP521_CERT_V1;
                break;

            case PublicKeyAlgorithmExt.ALGORITHM_ED25519:
                algo = PublicKeyAlgorithm.ED25519;
                break;

            case PublicKeyAlgorithmExt.ALGORITHM_ED25519_CERT_V1:
                algo = PublicKeyAlgorithm.ED25519_CERT_V1;
                break;

            default:
                algo = default(PublicKeyAlgorithm);
                return(false);
            }

            return(true);
        }
Пример #17
0
        public static EdwardsCurve FindByAlgorithm(PublicKeyAlgorithm algorithm)
        {
            switch (algorithm)
            {
            case PublicKeyAlgorithm.ED25519:
                return(FindByName("edwards25519"));

            default:
                return(null);
            }
        }
Пример #18
0
 public static string PublicKeyAlgorithmName(PublicKeyAlgorithm algorithm)
 {
     switch (algorithm) {
         case PublicKeyAlgorithm.DSA:
             return "ssh-dss";
         case PublicKeyAlgorithm.RSA:
             return "ssh-rsa";
         default:
             throw new SSHException("unknown HostKeyAlgorithm " + algorithm);
     }
 }
Пример #19
0
        public static PublicKeyAlgorithm[] ParsePublicKeyAlgorithm(string[] t)
        {
            PublicKeyAlgorithm[] ret = new PublicKeyAlgorithm[t.Length];
            int i = 0;

            foreach (string a in t)
            {
                ret[i++] = ParsePublicKeyAlgorithm(a);
            }
            return(ret);
        }
Пример #20
0
        public override void Parse(TreeBuilder tree)
        {
            tree.SetBookMark();
            Version = tree.ReadByte("Version");
            tree.ReadFormatted("Creation Time", BlockFormat.UnixTime);
            if (Version == 2 || Version == 3 || Version == 4)
            {
                if (Version != 4)
                {
                    tree.ReadNumber("Days Valid", 2);
                }
            }
            else
            {
                throw new NotImplementedException("Unknown Public Key Packet Version Code: " + Version.ToString());
            }

            byte AlgoCode = tree.ReadByte("Public Key Algorithm", PKAlgorithmTypes.Get);

            PublicKeyAlgorithm = PKAlgorithm.CreatePKAlgorithm(AlgoCode);

            if (PublicKeyAlgorithm == null)
            {
                tree.ReadBytes("Unknown Public Key Algorithm");
                return;
            }

            PublicKeyAlgorithm.LoadPublicKey(tree);
            PacketDataPublicKey = tree.ReadBytesFromBookMark();


            if (Version < 4)
            {
                // Only RSA is supported
                var ModN = ((RSA)PublicKeyAlgorithm).ModN;
                //KeyId = BitConverter.ToString(ModN, ModN.Length - 8);
                KeyId = ModN.SubArray(ModN.Length - 8, 8);
            }
            else
            {
                int  l    = PacketDataPublicKey.Length;
                SHA1 shaM = new SHA1Managed();

                byte[] HashContext = new byte[l + 3];
                HashContext[0] = 0x99;
                HashContext[1] = (byte)((l & 0xFF00) >> 8);
                HashContext[2] = (byte)(l & 0x00FF);
                Array.Copy(PacketDataPublicKey, 0, HashContext, 3, l);
                byte[] result = shaM.ComputeHash(HashContext);
                //KeyId = BitConverter.ToString(result, result.Length - 8);
                KeyId = result.SubArray(result.Length - 8, 8);
            }
            tree.AddCalculated("Key Id", BitConverter.ToString(KeyId), KeyId);
        }
Пример #21
0
        internal static EDDSAPublicKey ReadFrom(PublicKeyAlgorithm algorithm, SSH2DataReader reader)
        {
            EdwardsCurve curve = EdwardsCurve.FindByAlgorithm(algorithm);

            if (curve == null)
            {
                throw new SSHException(Strings.GetString("UnsupportedEllipticCurve"));
            }

            byte[] q = reader.ReadByteString();
            return(new EDDSAPublicKey(curve, q));
        }
Пример #22
0
        public byte[] Sign(byte[] data)
        {
            PublicKeyAlgorithm a = _keypair.Algorithm;

            if (a == PublicKeyAlgorithm.RSA)
            {
                return(((RSAKeyPair)_keypair).SignWithSHA1(data));
            }
            else
            {
                return(((DSAKeyPair)_keypair).Sign(new SHA1CryptoServiceProvider().ComputeHash(data)));
            }
        }
Пример #23
0
        public byte[] Sign([ReadOnlyArray()] byte[] data)
        {
            PublicKeyAlgorithm a = _keypair.Algorithm;

            if (a == PublicKeyAlgorithm.RSA)
            {
                return(((RSAKeyPair)_keypair).SignWithSHA1(data));
            }
            else
            {
                return(((DSAKeyPair)_keypair).Sign(HashAlgorithmProvider.OpenAlgorithm(HashAlgorithmNames.Sha1).HashData(data.AsBuffer()).ToArray()));
            }
        }
Пример #24
0
        /// <summary>
        /// Append missing algorithm to the list of <see cref="PublicKeyAlgorithm"/>.
        /// </summary>
        /// <param name="algorithms">list of <see cref="PublicKeyAlgorithm"/></param>
        /// <returns>new array of of <see cref="PublicKeyAlgorithm"/></returns>
        public static PublicKeyAlgorithm[] AppendMissingPublicKeyAlgorithm(PublicKeyAlgorithm[] algorithms)
        {
            var enumSet = new HashSet<PublicKeyAlgorithm>((PublicKeyAlgorithm[])Enum.GetValues(typeof(PublicKeyAlgorithm)));
            foreach (var a in algorithms) {
                enumSet.Remove(a);
            }
            var listToAppend = new List<PublicKeyAlgorithm>(enumSet);
            listToAppend.Sort((a1, a2) => a2.GetDefaultPriority().CompareTo(a1.GetDefaultPriority()));    // descending order

            var list = new List<PublicKeyAlgorithm>(algorithms.Length + listToAppend.Count);
            list.AddRange(algorithms);
            list.AddRange(listToAppend);
            return list.ToArray();
        }
Пример #25
0
        public static string PublicKeyAlgorithmName(PublicKeyAlgorithm algorithm)
        {
            switch (algorithm)
            {
            case PublicKeyAlgorithm.DSA:
                return("ssh-dss");

            case PublicKeyAlgorithm.RSA:
                return("ssh-rsa");

            default:
                throw new SSHException("unknown HostKeyAlgorithm " + algorithm);
            }
        }
Пример #26
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="hostName">Host name</param>
 /// <param name="portNumber">port number</param>
 /// <param name="protocol">SSH protocol version</param>
 /// <param name="authType">authentication type</param>
 /// <param name="userName">user name for login</param>
 /// <param name="password">password for login. pass empty string for the keyboard interactive mode.</param>
 public SSHConnectionParameter(string hostName, int portNumber, SSHProtocol protocol, AuthenticationType authType, string userName, string password)
 {
     HostName = hostName;
     PortNumber = portNumber;
     Protocol = protocol;
     PreferableCipherAlgorithms = new CipherAlgorithm[] { CipherAlgorithm.AES256CTR, CipherAlgorithm.AES256, CipherAlgorithm.AES192CTR, CipherAlgorithm.AES192, CipherAlgorithm.AES128CTR, CipherAlgorithm.AES128, CipherAlgorithm.Blowfish, CipherAlgorithm.TripleDES };
     PreferableHostKeyAlgorithms = new PublicKeyAlgorithm[] { PublicKeyAlgorithm.DSA, PublicKeyAlgorithm.RSA };
     AuthenticationType = authType;
     UserName = userName;
     Password = password;
     TerminalName = "vt100";
     WindowSize = 0x1000;
     MaxPacketSize = 0x10000;
     CheckMACError = true;
 }
Пример #27
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="hostName">Host name</param>
 /// <param name="portNumber">port number</param>
 /// <param name="protocol">SSH protocol version</param>
 /// <param name="authType">authentication type</param>
 /// <param name="userName">user name for login</param>
 /// <param name="password">password for login. pass empty string for the keyboard interactive mode.</param>
 public SSHConnectionParameter(string hostName, int portNumber, SSHProtocol protocol, AuthenticationType authType, string userName, string password)
 {
     HostName   = hostName;
     PortNumber = portNumber;
     Protocol   = protocol;
     PreferableCipherAlgorithms  = new CipherAlgorithm[] { CipherAlgorithm.AES256CTR, CipherAlgorithm.AES256, CipherAlgorithm.AES192CTR, CipherAlgorithm.AES192, CipherAlgorithm.AES128CTR, CipherAlgorithm.AES128, CipherAlgorithm.Blowfish, CipherAlgorithm.TripleDES };
     PreferableHostKeyAlgorithms = new PublicKeyAlgorithm[] { PublicKeyAlgorithm.DSA, PublicKeyAlgorithm.RSA };
     AuthenticationType          = authType;
     UserName         = userName;
     Password         = password;
     TerminalName     = "vt100";
     WindowSize       = 0x1000;
     MaxPacketSize    = 0x10000;
     CheckMACError    = true;
     VerifySSHHostKey = p => true;
 }
Пример #28
0
        public static string GetIdentifierString(this PublicKeyAlgorithm aPublicKeyAlgorithm)
        {
            switch (aPublicKeyAlgorithm)
            {
            case PublicKeyAlgorithm.SSH_RSA:
                return(ALGORITHM_RSA_KEY);

            case PublicKeyAlgorithm.SSH_RSA_CERT_V1:
                return(ALGORITHM_RSA_CERT_V1);

            case PublicKeyAlgorithm.SSH_DSS:
                return(ALGORITHM_DSA_KEY);

            case PublicKeyAlgorithm.SSH_DSS_CERT_V1:
                return(ALGORITHM_DSA_CERT_V1);

            case PublicKeyAlgorithm.ECDSA_SHA2_NISTP256:
                return(ALGORITHM_ECDSA_SHA2_NISTP256_KEY);

            case PublicKeyAlgorithm.ECDSA_SHA2_NISTP256_CERT_V1:
                return(ALGORITHM_ECDSA_SHA2_NISTP256_CERT_V1);

            case PublicKeyAlgorithm.ECDSA_SHA2_NISTP384:
                return(ALGORITHM_ECDSA_SHA2_NISTP384_KEY);

            case PublicKeyAlgorithm.ECDSA_SHA2_NISTP384_CERT_V1:
                return(ALGORITHM_ECDSA_SHA2_NISTP384_CERT_V1);

            case PublicKeyAlgorithm.ECDSA_SHA2_NISTP521:
                return(ALGORITHM_ECDSA_SHA2_NISTP521_KEY);

            case PublicKeyAlgorithm.ECDSA_SHA2_NISTP521_CERT_V1:
                return(ALGORITHM_ECDSA_SHA2_NISTP521_CERT_V1);

            case PublicKeyAlgorithm.ED25519:
                return(ALGORITHM_ED25519);

            case PublicKeyAlgorithm.ED25519_CERT_V1:
                return(ALGORITHM_ED25519_CERT_V1);

            default:
                Debug.Fail("Unknown algorithm");
                throw new Exception("Unknown algorithm");
            }
        }
Пример #29
0
 public static int GetSecretMPICount(PublicKeyAlgorithm pkAlgorithm)
 {
     if (pkAlgorithm.Equals(PublicKeyAlgorithm.DSA))
     {
         return(DSA_SECRET_KEY_MPI_COUNT);
     }
     else if (pkAlgorithm.Equals(PublicKeyAlgorithm.ElGamalEncryptOnly))
     {
         return(ELGAMAL_ENCRYPT_ONLY_SECRET_KEY_MPI_COUNT);
     }
     else if (pkAlgorithm.Equals(PublicKeyAlgorithm.RSA))
     {
         return(RSA_SECRET_KEY_MPI_COUNT);
     }
     else
     {
         return(0);
     }
 }
Пример #30
0
 public static int GetPublicMPICount(PublicKeyAlgorithm pkAlgorithm)
 {
     if (pkAlgorithm.Equals(PublicKeyAlgorithm.DSA))
     {
         return(Constants.DSA_PUBLIC_KEY_MPI_COUNT);
     }
     else if (pkAlgorithm.Equals(PublicKeyAlgorithm.ElGamalEncryptOnly))
     {
         return(Constants.ELGAMAL_ENCRYPT_ONLY_PUBLIC_KEY_MPI_COUNT);
     }
     else if (pkAlgorithm.Equals(PublicKeyAlgorithm.RSA))
     {
         return(Constants.RSA_PUBLIC_KEY_MPI_COUNT);
     }
     else
     {
         return(0);
     }
 }
Пример #31
0
        public void VerifyMultipartSigned(MimeMessage message)
        {
            if (message.Body is MultipartSigned)
            {
                var signed = (MultipartSigned)message.Body;

                foreach (var signature in signed.Verify())
                {
                    try
                    {
                        PublicKeyAlgorithm pubAlg = signature.PublicKeyAlgorithm;

                        bool valid = signature.Verify();
                    }
                    catch (DigitalSignatureVerifyException e)
                    {
                        Console.WriteLine(e.InnerException.ToString());
                    }
                }
            }
        }
        public bool Commit(IProtocolOptions options, IKeyAgentOptions agent)
        {
            StringResource sr = OptionDialogPlugin.Instance.Strings;

            //暗号アルゴリズム順序はoptionsを直接いじっているのでここでは何もしなくてよい
            try {
                PublicKeyAlgorithm[] pa = new PublicKeyAlgorithm[2];
                if (_hostKeyBox.SelectedIndex == 0)
                {
                    pa[0] = PublicKeyAlgorithm.DSA;
                    pa[1] = PublicKeyAlgorithm.RSA;
                }
                else
                {
                    pa[0] = PublicKeyAlgorithm.RSA;
                    pa[1] = PublicKeyAlgorithm.DSA;
                }
                options.HostKeyAlgorithmOrder = FormatPublicKeyAlgorithmList(pa);

                try {
                    options.SSHWindowSize = Int32.Parse(_windowSizeBox.Text);
                }
                catch (FormatException) {
                    GUtil.Warning(this, sr.GetString("Message.OptionDialog.InvalidWindowSize"));
                    return(false);
                }

                options.RetainsPassphrase    = _retainsPassphrase.Checked;
                options.SSHCheckMAC          = _sshCheckMAC.Checked;
                options.CipherAlgorithmOrder = _cipherAlgorithmOrder;
                options.LogSSHEvents         = _sshEventLog.Checked;
                agent.EnableKeyAgent         = _enableAgentForward.Checked;

                return(true);
            }
            catch (Exception ex) {
                GUtil.Warning(this, ex.Message);
                return(false);
            }
        }
Пример #33
0
 /// <summary>
 /// Constructor
 /// </summary>
 public CurveEd25519()
 {
     _curveName          = "edwards25519";
     _publicKeyAlgorithm = PublicKeyAlgorithm.ED25519;
     _p = new BigInteger(BigIntegerConverter.ParseHex(
                             // 2^255 - 19
                             "7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"
                             ));
     _d = BigInteger.Parse(
         "37095705934669439343138083508754565189542113879843219016388785533085940283555"
         );
     _bx = BigInteger.Parse(
         "15112221349535400772501151409588531511454012693041857206046113283949847762202"
         );
     _by = BigInteger.Parse(
         "46316835694926478169428394003475163141307993866256225615783033603165251855960"
         );
     _l = new BigInteger(BigIntegerConverter.ParseHex(
                             // 2^252 + 0x14def9dea2f79cd65812631a5cf5d3ed
                             "1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"
                             ));
 }
Пример #34
0
        private void ExtractPrivateKey()
        {
            if (!PublicKeyAlgorithm.PrivateKeyDecrypted)
            {
                PinEntry frm    = new PinEntry();
                bool     Result = false;
                do
                {
                    if (frm.ShowDialog() == DialogResult.Cancel)
                    {
                        break;
                    }

                    Result = PublicKeyAlgorithm.DecryptS2K(frm.Password);
                } while (!Result);

                if (Result)
                {
                    SecretKeyNode.AddChildBlock(PublicKeyAlgorithm.GetPrivateByteBlocks());
                }
            }
        }
Пример #35
0
 /// <summary>
 /// Constructor
 /// </summary>
 public CurveEd25519()
 {
     _curveName = "edwards25519";
     _publicKeyAlgorithm = PublicKeyAlgorithm.ED25519;
     _p = new BigInteger(BigIntegerConverter.ParseHex(
             // 2^255 - 19
             "7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"
         ));
     _d = BigInteger.Parse(
             "37095705934669439343138083508754565189542113879843219016388785533085940283555"
         );
     _bx = BigInteger.Parse(
             "15112221349535400772501151409588531511454012693041857206046113283949847762202"
         );
     _by = BigInteger.Parse(
             "46316835694926478169428394003475163141307993866256225615783033603165251855960"
         );
     _l = new BigInteger(BigIntegerConverter.ParseHex(
             // 2^252 + 0x14def9dea2f79cd65812631a5cf5d3ed
             "1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"
         ));
 }
Пример #36
0
        public bool Commit(IProtocolOptions options, IKeyAgentOptions agent)
        {
            StringResource sr = OptionDialogPlugin.Instance.Strings;
            //暗号アルゴリズム順序はoptionsを直接いじっているのでここでは何もしなくてよい
            try {
                PublicKeyAlgorithm[] pa = new PublicKeyAlgorithm[2];
                if (_hostKeyBox.SelectedIndex == 0) {
                    pa[0] = PublicKeyAlgorithm.DSA;
                    pa[1] = PublicKeyAlgorithm.RSA;
                }
                else {
                    pa[0] = PublicKeyAlgorithm.RSA;
                    pa[1] = PublicKeyAlgorithm.DSA;
                }
                options.HostKeyAlgorithmOrder = FormatPublicKeyAlgorithmList(pa);

                try {
                    options.SSHWindowSize = Int32.Parse(_windowSizeBox.Text);
                }
                catch (FormatException) {
                    GUtil.Warning(this, sr.GetString("Message.OptionDialog.InvalidWindowSize"));
                    return false;
                }

                options.RetainsPassphrase = _retainsPassphrase.Checked;
                options.SSHCheckMAC = _sshCheckMAC.Checked;
                options.CipherAlgorithmOrder = _cipherAlgorithmOrder;
                options.LogSSHEvents = _sshEventLog.Checked;
                agent.EnableKeyAgent = _enableAgentForward.Checked;

                return true;
            }
            catch (Exception ex) {
                GUtil.Warning(this, ex.Message);
                return false;
            }
        }
Пример #37
0
        public override bool Commit(ContainerOptions options)
        {
            //暗号アルゴリズム順序はoptionsを直接いじっているのでここでは何もしなくてよい
            try {
                PublicKeyAlgorithm[] pa = new PublicKeyAlgorithm[2];
                if (_hostKeyBox.SelectedIndex == 0)
                {
                    pa[0] = PublicKeyAlgorithm.DSA;
                    pa[1] = PublicKeyAlgorithm.RSA;
                }
                else
                {
                    pa[0] = PublicKeyAlgorithm.RSA;
                    pa[1] = PublicKeyAlgorithm.DSA;
                }
                options.HostKeyAlgorithmOrder = LocalSSHUtil.FormatPublicKeyAlgorithmList(pa);

                try {
                    options.SSHWindowSize = Int32.Parse(_windowSizeBox.Text);
                }
                catch (FormatException) {
                    GUtil.Warning(this, GApp.Strings.GetString("Message.OptionDialog.InvalidWindowSize"));
                    return(false);
                }

                options.RetainsPassphrase    = _retainsPassphrase.Checked;
                options.SSHCheckMAC          = _sshCheckMAC.Checked;
                options.CipherAlgorithmOrder = _cipherAlgorithmOrder;

                return(true);
            }
            catch (Exception ex) {
                GUtil.Warning(this, ex.Message);
                return(false);
            }
        }
Пример #38
0
        internal static EDDSAPublicKey ReadFrom(PublicKeyAlgorithm algorithm, SSH2DataReader reader)
        {
            EdwardsCurve curve = EdwardsCurve.FindByAlgorithm(algorithm);
            if (curve == null) {
                throw new SSHException(Strings.GetString("UnsupportedEllipticCurve"));
            }

            byte[] q = reader.ReadByteString();
            return new EDDSAPublicKey(curve, q);
        }
 public CertificateBitStrength(PublicKeyAlgorithm algorithmName, int?bitSize)
 {
     AlgorithmName = algorithmName;
     BitSize       = bitSize;
 }
 public CertificateBitStrength(PublicKeyAlgorithm algorithmName, int? bitSize)
 {
     AlgorithmName = algorithmName;
     BitSize = bitSize;
 }
Пример #41
0
 public static EdwardsCurve FindByAlgorithm(PublicKeyAlgorithm algorithm)
 {
     switch (algorithm) {
         case PublicKeyAlgorithm.ED25519:
             return FindByName("edwards25519");
         default:
             return null;
     }
 }
Пример #42
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="algorithm">public key algorithm which uses this curve</param>
 /// <param name="curveName">curve name</param>
 /// <param name="m">exponent of 2</param>
 /// <param name="exp">exponents of x</param>
 /// <param name="a">curve parameter</param>
 /// <param name="b">curve parameter</param>
 /// <param name="G">base point</param>
 /// <param name="n">order n of G</param>
 /// <param name="h">cofactor</param>
 public EllipticCurveF2m(
         PublicKeyAlgorithm algorithm, string curveName,
         int m, int[] exp, byte[] a, byte[] b, ECPoint G, BigInteger n, BigInteger h) {
     this._algorithm = algorithm;
     this._curveName = curveName;
     this.m = m;
     this.Exp = exp;
     this.a = a;
     this.b = b;
     this.G = G;
     this.n = n;
     this.h = h;
 }
Пример #43
0
 public static int GetTotalMPICount(PublicKeyAlgorithm pkAlgorithm)
 {
     return GetPublicMPICount(pkAlgorithm) + GetSecretMPICount(pkAlgorithm);
 }
Пример #44
0
 public PublicKeyAlgorithmListItem(PublicKeyAlgorithm value)
 {
     this.Value = value;
     this.AlgorithmName = value.GetAlgorithmName();
 }
Пример #45
0
        public override void Parse(TreeBuilder tree)
        {
            base.Parse(tree);

            bool IsEncrypted = true;

            tree.SetBookMark();
            var S2K = new S2K
            {
                S2KUsage = tree.ReadByte()
            };

            if (S2K.S2KUsage == 254 || S2K.S2KUsage == 255)
            {
                S2K.SymAlgo = tree.ReadByte("Symmetric Algorithm", SymmetricAlgorithmTypes.Get);

                byte S2KSpecifier = tree.ReadByte("S2K Specifier", S2KTypes.Get);

                if (S2KSpecifier != S2KTypes.Salted && S2KSpecifier != S2KTypes.Simple && S2KSpecifier != S2KTypes.IteratedAndSalted)
                {
                    //tree.AddCalculated("Invalid S2K", S2KSpecifier.ToString());
                    tree.AddCalculated("Unable to Process", S2KSpecifier.ToString(), ByteBlockType.CalculatedError);
                    return;
                }

                S2K.HashAlgorithm = tree.ReadByte("Hash Algorithm", HashAlgorithmTypes.Get);

                if (S2KSpecifier == S2KTypes.Salted || S2KSpecifier == S2KTypes.IteratedAndSalted)
                {
                    S2K.Salt = tree.ReadBytes("Salt", 8);
                    if (S2KSpecifier == S2KTypes.IteratedAndSalted)
                    {
                        byte CodedCount = tree.ReadByte("Coded Iteration");
                        S2K.ByteCount = (16 + (CodedCount & 15)) << ((CodedCount >> 4) + 6);
                    }
                }

                int BlockSizeBytes = SymmetricAlgorithmTypes.GetBlockSize(S2K.SymAlgo) / 8;
                S2K.IV = tree.ReadBytes("IV", BlockSizeBytes);
            }
            else
            {
                byte SymAlgo = S2K.S2KUsage;
                S2K.SymAlgo = SymAlgo;

                if (SymAlgo != 0)
                {
                    tree.GoToBookMark();
                    tree.ReadByte("Symmetric Algorithm", SymmetricAlgorithmTypes.Get);
                    int BlockSize = SymmetricAlgorithmTypes.GetBlockSize(SymAlgo) / 8;
                    S2K.IV = tree.ReadBytes("IV", BlockSize);
                }
                else
                {
                    IsEncrypted = false;
                }
            }

            PublicKeyAlgorithm.S2K = S2K;

            if (IsEncrypted)
            {
                byte[] Encrypted = tree.ReadBytes("Encrypted Secret Key");
                PublicKeyAlgorithm.EncryptedPrivateKey = Encrypted;
                tree.CurrentBlock.ProcessBlock        += ExtractPrivateKey;
                SecretKeyNode = tree.CurrentBlock;
            }
            else
            {
                byte[] ClearBytes = tree.ReadBytes("Unencrypted Secret Key");

                var SecBlockClear = PublicKeyAlgorithm.SetPrivate(ClearBytes);
                tree.AddChild(PublicKeyAlgorithm.GetPrivateByteBlocks());
            }
        }
Пример #46
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="algorithm">public key algorithm which uses this curve</param>
 /// <param name="curveName">curve name</param>
 /// <param name="p">odd prime</param>
 /// <param name="a">curve parameter</param>
 /// <param name="b">curve parameter</param>
 /// <param name="G">base point</param>
 /// <param name="n">order n of G</param>
 /// <param name="h">cofactor</param>
 public EllipticCurveFp(
         PublicKeyAlgorithm algorithm, string curveName,
         BigInteger p, BigInteger a, BigInteger b, ECPoint G, BigInteger n, BigInteger h) {
     this._algorithm = algorithm;
     this._curveName = curveName;
     this.p = p;
     this.a = a;
     this.b = b;
     this.G = G;
     this.n = n;
     this.h = h;
 }
Пример #47
0
        public static SshKey CreateKey(SshVersion version,
      PublicKeyAlgorithm algorithm, string comment = "")
        {
            if (version == SshVersion.SSH1 &&
            algorithm != PublicKeyAlgorithm.SSH_RSA) {
            throw new Exception("unsupported version/algorithm combination");
              }

              switch (algorithm) {
            case PublicKeyAlgorithm.SSH_RSA:
              KeyGenerationParameters keyGenParam =
            new KeyGenerationParameters(secureRandom, 512);

              RsaKeyPairGenerator rsaKeyPairGen = new RsaKeyPairGenerator();
              rsaKeyPairGen.Init(keyGenParam);
              AsymmetricCipherKeyPair keyPair = rsaKeyPairGen.GenerateKeyPair();
              var rsaKey = new SshKey(version, keyPair);
              rsaKey.Comment = comment;
              return rsaKey;

            case PublicKeyAlgorithm.SSH_DSS:
              DsaParametersGenerator dsaParamGen = new DsaParametersGenerator();
              dsaParamGen.Init(512, 10, secureRandom);
              DsaParameters dsaParam = dsaParamGen.GenerateParameters();
              DsaKeyGenerationParameters dsaKeyGenParam =
            new DsaKeyGenerationParameters(secureRandom, dsaParam);
              DsaKeyPairGenerator dsaKeyPairGen = new DsaKeyPairGenerator();
              dsaKeyPairGen.Init(dsaKeyGenParam);
              keyPair = dsaKeyPairGen.GenerateKeyPair();
              var dsaKey = new SshKey(SshVersion.SSH2, keyPair);
              dsaKey.Comment = comment;
              return dsaKey;

            case PublicKeyAlgorithm.ECDSA_SHA2_NISTP256:
              X9ECParameters ecdsa256X9Params =
            SecNamedCurves.GetByName("secp256r1");
              ECDomainParameters ecdsa256DomainParams =
            new ECDomainParameters(ecdsa256X9Params.Curve, ecdsa256X9Params.G,
              ecdsa256X9Params.N, ecdsa256X9Params.H);
              ECKeyGenerationParameters ecdsa256GenParams =
            new ECKeyGenerationParameters(ecdsa256DomainParams, secureRandom);
              ECKeyPairGenerator ecdsa256Gen = new ECKeyPairGenerator();
              ecdsa256Gen.Init(ecdsa256GenParams);
              keyPair = ecdsa256Gen.GenerateKeyPair();
              var ecdsa256Key = new SshKey(SshVersion.SSH2, keyPair);
              ecdsa256Key.Comment = comment;
              return ecdsa256Key;

            case PublicKeyAlgorithm.ECDSA_SHA2_NISTP384:
              X9ECParameters ecdsa384X9Params =
            SecNamedCurves.GetByName("secp384r1");
              ECDomainParameters ecdsa384DomainParams =
            new ECDomainParameters(ecdsa384X9Params.Curve, ecdsa384X9Params.G,
              ecdsa384X9Params.N, ecdsa384X9Params.H);
              ECKeyGenerationParameters ecdsa384GenParams =
            new ECKeyGenerationParameters(ecdsa384DomainParams, secureRandom);
              ECKeyPairGenerator ecdsa384Gen = new ECKeyPairGenerator();
              ecdsa384Gen.Init(ecdsa384GenParams);
              keyPair = ecdsa384Gen.GenerateKeyPair();
              var ecdsa384Key = new SshKey(SshVersion.SSH2, keyPair);
              ecdsa384Key.Comment = comment;
              return ecdsa384Key;

            case PublicKeyAlgorithm.ECDSA_SHA2_NISTP521:
              X9ECParameters ecdsa521X9Params =
            SecNamedCurves.GetByName("secp521r1");
              ECDomainParameters ecdsa521DomainParams =
            new ECDomainParameters(ecdsa521X9Params.Curve, ecdsa521X9Params.G,
              ecdsa521X9Params.N, ecdsa521X9Params.H);
              ECKeyGenerationParameters ecdsa521GenParams =
            new ECKeyGenerationParameters(ecdsa521DomainParams, secureRandom);
              ECKeyPairGenerator ecdsa521Gen = new ECKeyPairGenerator();
              ecdsa521Gen.Init(ecdsa521GenParams);
              keyPair = ecdsa521Gen.GenerateKeyPair();
              var ecdsa521Key = new SshKey(SshVersion.SSH2, keyPair);
              ecdsa521Key.Comment = comment;
              return ecdsa521Key;

            case PublicKeyAlgorithm.ED25519:
              var privateKeySeed = secureRandom.GenerateSeed(Ed25519.PrivateKeySeedSizeInBytes);
              var publicKeyBytes = new byte[Ed25519.PublicKeySizeInBytes];
              var privateKeyBytes = new byte[Ed25519.ExpandedPrivateKeySizeInBytes];
              Ed25519.KeyPairFromSeed(out publicKeyBytes, out privateKeyBytes, privateKeySeed);
              var publicKey = new Ed25519PublicKeyParameter(publicKeyBytes);
              var privateKey = new Ed25519PrivateKeyParameter(privateKeyBytes);
              var ed25519Key = new SshKey(SshVersion.SSH2, publicKey, privateKey, comment);
              return ed25519Key;

            default:
              throw new Exception("unsupported algorithm");
              }
        }
Пример #48
0
        private static AsymmetricCipherKeyPair CreateCipherKeyPair(
      PublicKeyAlgorithm algorithm,
      byte[] publicKeyBlob, byte[] privateKeyBlob)
        {
            var parser = new BlobParser(publicKeyBlob);
              var publicKey = parser.ReadSsh2PublicKeyData();
              parser = new BlobParser(privateKeyBlob);

              switch (algorithm) {
            case PublicKeyAlgorithm.SSH_RSA:
              var rsaPublicKeyParams = (RsaKeyParameters)publicKey;

              var d = new BigInteger(1, parser.ReadBlob());
              var p = new BigInteger(1, parser.ReadBlob());
              var q = new BigInteger(1, parser.ReadBlob());
              var inverseQ = new BigInteger(1, parser.ReadBlob());

              /* compute missing parameters */
              var dp = d.Remainder(p.Subtract(BigInteger.One));
              var dq = d.Remainder(q.Subtract(BigInteger.One));

              RsaPrivateCrtKeyParameters rsaPrivateKeyParams =
            new RsaPrivateCrtKeyParameters(rsaPublicKeyParams.Modulus,
              rsaPublicKeyParams.Exponent, d, p, q, dp, dq, inverseQ);

              return new AsymmetricCipherKeyPair(rsaPublicKeyParams,
            rsaPrivateKeyParams);

            case PublicKeyAlgorithm.SSH_DSS:
              var dsaPublicKeyParams = (DsaPublicKeyParameters)publicKey;

              var x = new BigInteger(1, parser.ReadBlob());
              DsaPrivateKeyParameters dsaPrivateKeyParams =
            new DsaPrivateKeyParameters(x, dsaPublicKeyParams.Parameters);

              return new AsymmetricCipherKeyPair(dsaPublicKeyParams,
            dsaPrivateKeyParams);
            case PublicKeyAlgorithm.ED25519:
              var ed25596PublicKey = (Ed25519PublicKeyParameter)publicKey;

              byte[] privBlob = parser.ReadBlob();
              byte[] privSig = new byte[64];
              // OpenSSH's "private key" is actually the private key with the public key tacked on ...
              Array.Copy(privBlob, 0, privSig, 0, 32);
              Array.Copy(ed25596PublicKey.Key, 0, privSig, 32, 32);
              var ed25596PrivateKey = new Ed25519PrivateKeyParameter(privSig);

              return new AsymmetricCipherKeyPair(ed25596PublicKey, ed25596PrivateKey);
            case PublicKeyAlgorithm.ECDSA_SHA2_NISTP256:
            case PublicKeyAlgorithm.ECDSA_SHA2_NISTP384:
            case PublicKeyAlgorithm.ECDSA_SHA2_NISTP521:
              var ecPublicKeyParams = (ECPublicKeyParameters)publicKey;

              var ecdsaPrivate = new BigInteger(1, parser.ReadBlob());
              ECPrivateKeyParameters ecPrivateKeyParams =
            new ECPrivateKeyParameters(ecdsaPrivate, ecPublicKeyParams.Parameters);

              return new AsymmetricCipherKeyPair(ecPublicKeyParams, ecPrivateKeyParams);
            default:
              // unsupported encryption algorithm
              throw new PpkFormatterException(PpkFormatterException.PpkErrorType.PublicKeyEncryption);
              }
        }
Пример #49
0
 public Certificate(slice <byte> Raw = default, slice <byte> RawTBSCertificate = default, slice <byte> RawSubjectPublicKeyInfo = default, slice <byte> RawSubject = default, slice <byte> RawIssuer = default, slice <byte> Signature = default, SignatureAlgorithm SignatureAlgorithm = default, PublicKeyAlgorithm PublicKeyAlgorithm = default, long Version = default, ref ptr <big.Int> SerialNumber = default, pkix.Name Issuer = default, pkix.Name Subject = default, time.Time NotBefore = default, time.Time NotAfter = default, KeyUsage KeyUsage = default, slice <pkix.Extension> Extensions = default, slice <pkix.Extension> ExtraExtensions = default, slice <asn1.ObjectIdentifier> UnhandledCriticalExtensions = default, slice <ExtKeyUsage> ExtKeyUsage = default, slice <asn1.ObjectIdentifier> UnknownExtKeyUsage = default, bool BasicConstraintsValid = default, bool IsCA = default, long MaxPathLen = default, bool MaxPathLenZero = default, slice <byte> SubjectKeyId = default, slice <byte> AuthorityKeyId = default, slice <@string> OCSPServer = default, slice <@string> IssuingCertificateURL = default, slice <@string> DNSNames = default, slice <@string> EmailAddresses = default, slice <net.IP> IPAddresses = default, slice <ptr <url.URL> > URIs = default, bool PermittedDNSDomainsCritical = default, slice <@string> PermittedDNSDomains = default, slice <@string> ExcludedDNSDomains = default, slice <ptr <net.IPNet> > PermittedIPRanges = default, slice <ptr <net.IPNet> > ExcludedIPRanges = default, slice <@string> PermittedEmailAddresses = default, slice <@string> ExcludedEmailAddresses = default, slice <@string> PermittedURIDomains = default, slice <@string> ExcludedURIDomains = default, slice <@string> CRLDistributionPoints = default, slice <asn1.ObjectIdentifier> PolicyIdentifiers = default)
 {
     this.Raw = Raw;
     this.RawTBSCertificate       = RawTBSCertificate;
     this.RawSubjectPublicKeyInfo = RawSubjectPublicKeyInfo;
     this.RawSubject                  = RawSubject;
     this.RawIssuer                   = RawIssuer;
     this.Signature                   = Signature;
     this.SignatureAlgorithm          = SignatureAlgorithm;
     this.PublicKeyAlgorithm          = PublicKeyAlgorithm;
     this.Version                     = Version;
     this.SerialNumber                = SerialNumber;
     this.Issuer                      = Issuer;
     this.Subject                     = Subject;
     this.NotBefore                   = NotBefore;
     this.NotAfter                    = NotAfter;
     this.KeyUsage                    = KeyUsage;
     this.Extensions                  = Extensions;
     this.ExtraExtensions             = ExtraExtensions;
     this.UnhandledCriticalExtensions = UnhandledCriticalExtensions;
     this.ExtKeyUsage                 = ExtKeyUsage;
     this.UnknownExtKeyUsage          = UnknownExtKeyUsage;
     this.BasicConstraintsValid       = BasicConstraintsValid;
     this.IsCA                        = IsCA;
     this.MaxPathLen                  = MaxPathLen;
     this.MaxPathLenZero              = MaxPathLenZero;
     this.SubjectKeyId                = SubjectKeyId;
     this.AuthorityKeyId              = AuthorityKeyId;
     this.OCSPServer                  = OCSPServer;
     this.IssuingCertificateURL       = IssuingCertificateURL;
     this.DNSNames                    = DNSNames;
     this.EmailAddresses              = EmailAddresses;
     this.IPAddresses                 = IPAddresses;
     this.URIs                        = URIs;
     this.PermittedDNSDomainsCritical = PermittedDNSDomainsCritical;
     this.PermittedDNSDomains         = PermittedDNSDomains;
     this.ExcludedDNSDomains          = ExcludedDNSDomains;
     this.PermittedIPRanges           = PermittedIPRanges;
     this.ExcludedIPRanges            = ExcludedIPRanges;
     this.PermittedEmailAddresses     = PermittedEmailAddresses;
     this.ExcludedEmailAddresses      = ExcludedEmailAddresses;
     this.PermittedURIDomains         = PermittedURIDomains;
     this.ExcludedURIDomains          = ExcludedURIDomains;
     this.CRLDistributionPoints       = CRLDistributionPoints;
     this.PolicyIdentifiers           = PolicyIdentifiers;
 }
Пример #50
0
 public PublicKeyAlgorithmListItem(PublicKeyAlgorithm value)
 {
     this.Value         = value;
     this.AlgorithmName = value.GetAlgorithmName();
 }
Пример #51
0
        private bool CommitSSHOptions()
        {
            //�Í��A���S���Y��������_options�𒼐ڂ������Ă���̂ł����ł͉�����Ȃ��Ă悢
            try {
                PublicKeyAlgorithm[] pa = new PublicKeyAlgorithm[2];
                if(_hostKeyBox.SelectedIndex==0) {
                    pa[0] = PublicKeyAlgorithm.DSA;
                    pa[1] = PublicKeyAlgorithm.RSA;
                }
                else {
                    pa[0] = PublicKeyAlgorithm.RSA;
                    pa[1] = PublicKeyAlgorithm.DSA;
                }
                _options.HostKeyAlgorithmOrder = SSHUtil.FormatPublicKeyAlgorithmList(pa);

                try {
                    _options.SSHWindowSize = Int32.Parse(_windowSizeBox.Text);
                }
                catch(FormatException) {
                    Util.Warning(this, Env.Strings.GetString("Message.OptionDialog.InvalidWindowSize"));
                    return false;
                }

                _options.RetainsPassphrase = _retainsPassphrase.Checked;
                _options.SSHCheckMAC = _sshCheckMAC.Checked;

                return true;
            }
            catch(Exception ex) {
                Util.Warning(this, ex.Message);
                return false;
            }
        }
Пример #52
0
   public static bool TryParsePublicKeyAlgorithm(this string aString,
 ref PublicKeyAlgorithm aAlgorithm)
   {
       switch (aString) {
       case PublicKeyAlgorithmExt.ALGORITHM_RSA_KEY:
         aAlgorithm = PublicKeyAlgorithm.SSH_RSA;
         return true;
       case PublicKeyAlgorithmExt.ALGORITHM_DSA_KEY:
         aAlgorithm = PublicKeyAlgorithm.SSH_DSS;
         return true;
       case PublicKeyAlgorithmExt.ALGORITHM_ECDSA_SHA2_NISTP256_KEY:
         aAlgorithm = PublicKeyAlgorithm.ECDSA_SHA2_NISTP256;
         return true;
       case PublicKeyAlgorithmExt.ALGORITHM_ECDSA_SHA2_NISTP384_KEY:
         aAlgorithm = PublicKeyAlgorithm.ECDSA_SHA2_NISTP384;
         return true;
       case PublicKeyAlgorithmExt.ALGORITHM_ECDSA_SHA2_NISTP521_KEY:
         aAlgorithm = PublicKeyAlgorithm.ECDSA_SHA2_NISTP521;
         return true;
       case PublicKeyAlgorithmExt.ALGORITHM_ED25519:
         aAlgorithm = PublicKeyAlgorithm.ED25519;
         return true;
       default:
         return false;
         }
   }