示例#1
0
 private void _RefreshCredentialListFromFile()
 {
     this._credentialList.Clear();
     // Determine number of credentials in the credentials file.
     System.UInt32 nrOfCredentials = this._credentialFile.NumberOfCertificates;
     for (System.UInt32 index = 0; index < nrOfCredentials; index++)
     {
         Wrappers.MCertificate internalCredential = this._credentialFile.get_Certificate(index);
         this._credentialList.Add(new Credential(internalCredential));
     }
     return;
 }
示例#2
0
 private void _RefreshCertificateListFromFile()
 {
     this._certificateList.Clear();
     // Determine number of certificates in the certificate file.
     System.UInt32 nrOfCertificates = this._certificateFile.NumberOfCertificates;
     for (System.UInt32 index = 0; index < nrOfCertificates; index++)
     {
         Wrappers.MCertificate internalCertificate = this._certificateFile.get_Certificate(index);
         this._certificateList.Add(new Certificate(internalCertificate));
     }
     return;
 }
示例#3
0
 /// <summary>
 /// Generate a certificate with the current settings.
 /// </summary>
 public void Generate()
 {
     //
     // Check pre-conditions for properties.
     //
     // Check the key length for specific key types
     //
     switch (this.SignatureAlgorithm)
     {
         case SignatureAlgorithm.RSA:
         {
             if ((this.SignatureKeyLength < 512) || (this.SignatureKeyLength > 2048))
             {
                 throw new System.ArgumentOutOfRangeException(
                     "RSA key length must be between 512 and 2048");
             }
             break;
         }
         case SignatureAlgorithm.DSA:
         {
             if ((this.SignatureKeyLength < 512) || (this.SignatureKeyLength > 1024))
             {
                 throw new System.ArgumentOutOfRangeException(
                     "DSA key length must be between 512 and 1024");
             }
             break;
         }
         default:
             //
             // Unknown SignatureAlgorithm
             //
             throw new System.NotImplementedException();
     }
     //
     // Check for illegal characters in CommonName
     //
     if (this.CommonName.IndexOf("/=") != -1)
     {
         throw new System.ArgumentOutOfRangeException(
             "The characters \"/\" and \"=\" are not allowed in a name field");
     }
     //
     // Check for illegal characters in OrganizationalUnit
     //
     if (this.OrganizationalUnit.IndexOf("/=") != -1)
     {
         throw new System.ArgumentOutOfRangeException(
             "The characters \"/\" and \"=\" are not allowed in a name field");
     }
     //
     // Check for illegal characters in Organizational
     //
     if (this.Organization.IndexOf("/=") != -1)
     {
         throw new System.ArgumentOutOfRangeException(
             "The characters \"/\" and \"=\" are not allowed in a name field");
     }
     //
     // Check for illegal characters in Locality
     //
     if (this.Locality.IndexOf("/=") != -1)
     {
         throw new System.ArgumentOutOfRangeException(
             "The characters \"/\" and \"=\" are not allowed in a name field");
     }
     //
     // Check for illegal characters in State
     //
     if (this.State.IndexOf("/=") != -1)
     {
         throw new System.ArgumentOutOfRangeException(
             "The characters \"/\" and \"=\" are not allowed in a name field");
     }
     //
     // Check for illegal characters in Country
     //
     if (this.Country.IndexOf("/=") != -1)
     {
         throw new System.ArgumentOutOfRangeException(
             "The characters \"/\" and \"=\" are not allowed in a name field");
     }
     //
     // Create certificate
     //
     Wrappers.MCertificate certificate = new Wrappers.MCertificate();
     //
     // Initialize certificate
     //
     // Only generating version 1 certificates
     //
     certificate.Version = 1;
     certificate.Subject =
         BuildSubjectName(
         this.CommonName,
         this.OrganizationalUnit,
         this.Organization,
         this.Locality,
         this.State,
         this.Country);
     certificate.EffectiveDate = this.ValidFromDate;
     certificate.ExpirationDate = this.ValidToDate;
     switch (this.SignatureAlgorithm)
     {
         case SignatureAlgorithm.RSA:
             certificate.SignatureAlgorithm = "RSA";
             break;
         case SignatureAlgorithm.DSA:
             certificate.SignatureAlgorithm = "DSA";
             break;
         default:
             //
             // Unknown SignatureAlgorithm
             //
             throw new System.NotImplementedException();
     }
     certificate.SignatureKeyLength = this.SignatureKeyLength;
     System.String credentialsFilePassword;
     if (
         this.CredentialsFilePassword == null ||
         this.CredentialsFilePassword == System.String.Empty)
     {
         //
         // use the default password for the credentials file if none is specified
         //
         credentialsFilePassword = DEFAULT_CERTIFICATE_FILE_PASSWORD;
     }
     else
     {
         credentialsFilePassword = this.CredentialsFilePassword;
     }
     System.String credentialsFile;
     if (this.SelfSign)
     {
         credentialsFile = null;
     }
     else
     {
         credentialsFile = this.CredentialsFile;
     }
     certificate.GenerateFiles(
         credentialsFile,
         credentialsFilePassword,
         this.PrivateKeyPassword,
         this.PrivateKeyFile,
         this.CertificateFile);
 }
示例#4
0
 // ctor
 internal Credential(Wrappers.MCertificate credential)
 {
     _credential = credential;
 }
示例#5
0
 // ctor
 internal Certificate(Wrappers.MCertificate certificate)
 {
     _certificate = certificate;
 }
示例#6
0
        /// <summary>
        /// Generate a certificate with the current settings.
        /// </summary>
        public void Generate()
        {
            //
            // Check pre-conditions for properties.
            //
            // Check the key length for specific key types
            //
            switch (this.SignatureAlgorithm)
            {
            case SignatureAlgorithm.RSA:
            {
                if ((this.SignatureKeyLength < 512) || (this.SignatureKeyLength > 2048))
                {
                    throw new System.ArgumentOutOfRangeException(
                              "RSA key length must be between 512 and 2048");
                }
                break;
            }

            case SignatureAlgorithm.DSA:
            {
                if ((this.SignatureKeyLength < 512) || (this.SignatureKeyLength > 1024))
                {
                    throw new System.ArgumentOutOfRangeException(
                              "DSA key length must be between 512 and 1024");
                }
                break;
            }

            default:
                //
                // Unknown SignatureAlgorithm
                //
                throw new System.NotImplementedException();
            }
            //
            // Check for illegal characters in CommonName
            //
            if (this.CommonName.IndexOf("/=") != -1)
            {
                throw new System.ArgumentOutOfRangeException(
                          "The characters \"/\" and \"=\" are not allowed in a name field");
            }
            //
            // Check for illegal characters in OrganizationalUnit
            //
            if (this.OrganizationalUnit.IndexOf("/=") != -1)
            {
                throw new System.ArgumentOutOfRangeException(
                          "The characters \"/\" and \"=\" are not allowed in a name field");
            }
            //
            // Check for illegal characters in Organizational
            //
            if (this.Organization.IndexOf("/=") != -1)
            {
                throw new System.ArgumentOutOfRangeException(
                          "The characters \"/\" and \"=\" are not allowed in a name field");
            }
            //
            // Check for illegal characters in Locality
            //
            if (this.Locality.IndexOf("/=") != -1)
            {
                throw new System.ArgumentOutOfRangeException(
                          "The characters \"/\" and \"=\" are not allowed in a name field");
            }
            //
            // Check for illegal characters in State
            //
            if (this.State.IndexOf("/=") != -1)
            {
                throw new System.ArgumentOutOfRangeException(
                          "The characters \"/\" and \"=\" are not allowed in a name field");
            }
            //
            // Check for illegal characters in Country
            //
            if (this.Country.IndexOf("/=") != -1)
            {
                throw new System.ArgumentOutOfRangeException(
                          "The characters \"/\" and \"=\" are not allowed in a name field");
            }
            //
            // Create certificate
            //
            Wrappers.MCertificate certificate = new Wrappers.MCertificate();
            //
            // Initialize certificate
            //
            // Only generating version 1 certificates
            //
            certificate.Version = 1;
            certificate.Subject =
                BuildSubjectName(
                    this.CommonName,
                    this.OrganizationalUnit,
                    this.Organization,
                    this.Locality,
                    this.State,
                    this.Country);
            certificate.EffectiveDate  = this.ValidFromDate;
            certificate.ExpirationDate = this.ValidToDate;
            switch (this.SignatureAlgorithm)
            {
            case SignatureAlgorithm.RSA:
                certificate.SignatureAlgorithm = "RSA";
                break;

            case SignatureAlgorithm.DSA:
                certificate.SignatureAlgorithm = "DSA";
                break;

            default:
                //
                // Unknown SignatureAlgorithm
                //
                throw new System.NotImplementedException();
            }
            certificate.SignatureKeyLength = this.SignatureKeyLength;
            System.String credentialsFilePassword;
            if (
                this.CredentialsFilePassword == null ||
                this.CredentialsFilePassword == System.String.Empty)
            {
                //
                // use the default password for the credentials file if none is specified
                //
                credentialsFilePassword = DEFAULT_CERTIFICATE_FILE_PASSWORD;
            }
            else
            {
                credentialsFilePassword = this.CredentialsFilePassword;
            }
            System.String credentialsFile;
            if (this.SelfSign)
            {
                credentialsFile = null;
            }
            else
            {
                credentialsFile = this.CredentialsFile;
            }
            certificate.GenerateFiles(
                credentialsFile,
                credentialsFilePassword,
                this.PrivateKeyPassword,
                this.PrivateKeyFile,
                this.CertificateFile);
        }
示例#7
0
 // ctor
 internal Certificate(Wrappers.MCertificate certificate)
 {
     _certificate = certificate;
 }
示例#8
0
 // ctor
 internal Credential(Wrappers.MCertificate credential)
 {
     _credential = credential;
 }