示例#1
0
文件: KeyId.cs 项目: sdmon/PgpSharp
 /// <summary>
 /// Initializes a new instance of the <see cref="KeyId" /> class.
 /// </summary>
 /// <param name="keyId">The key id.</param>
 /// <param name="fingerprint">The finger print.</param>
 /// <param name="allowedCapability">The allowed capability.</param>
 /// <param name="usableCapability">The usable capability.</param>
 /// <param name="userIds">The user ids.</param>
 public KeyId(string keyId, string fingerprint, KeyCapabilities allowedCapability, KeyCapabilities usableCapability, IEnumerable<string> userIds)
 {
     Id = keyId;
     Fingerprint = fingerprint;
     AllowedCapability = allowedCapability;
     UsableCapability = usableCapability;
     UserIds = userIds;
 }
示例#2
0
文件: KeyId.cs 项目: tigerxy/PgpSharp
 /// <summary>
 /// Initializes a new instance of the <see cref="KeyId" /> class.
 /// </summary>
 /// <param name="keyId">The key id.</param>
 /// <param name="fingerprint">The finger print.</param>
 /// <param name="allowedCapability">The allowed capability.</param>
 /// <param name="usableCapability">The usable capability.</param>
 /// <param name="userIds">The user ids.</param>
 public KeyId(string keyId, string fingerprint, KeyCapabilities allowedCapability, KeyCapabilities usableCapability, IEnumerable <string> userIds)
 {
     Id                = keyId;
     Fingerprint       = fingerprint;
     AllowedCapability = allowedCapability;
     UsableCapability  = usableCapability;
     UserIds           = userIds;
 }
示例#3
0
  /// <summary>Called to verify that the key matches is allowed in the collection.</summary>
  protected void ValidateKey(KeyType key)
  {
    if(key == null) throw new ArgumentNullException();

    PrimaryKey primaryKey = key as PrimaryKey;
    KeyCapabilities capabilities = primaryKey != null ? primaryKey.TotalCapabilities : key.Capabilities;

    if((capabilities & requiredCapabilities) != requiredCapabilities)
    {
      throw new ArgumentException("The key does not have all of the required capabilities: " +
                                  requiredCapabilities.ToString());
    }
  }
示例#4
0
        /// <summary>
        /// Parses the key capability field from list keys command.
        /// </summary>
        /// <param name="field">The field.</param>
        /// <param name="allowed">The allowed.</param>
        /// <param name="usable">The usable.</param>
        static void ParseKeyCapField(string field, ref KeyCapabilities allowed, ref KeyCapabilities usable)
        {
            foreach (char c in field)
            {
                switch (c)
                {
                case 'e':
                    allowed |= KeyCapabilities.Encrypt;
                    break;

                case 'E':
                    usable |= KeyCapabilities.Encrypt;
                    break;

                case 's':
                    allowed |= KeyCapabilities.Sign;
                    break;

                case 'S':
                    usable |= KeyCapabilities.Sign;
                    break;

                case 'c':
                    allowed |= KeyCapabilities.Certify;
                    break;

                case 'C':
                    usable |= KeyCapabilities.Certify;
                    break;

                case 'a':
                    allowed |= KeyCapabilities.Authentication;
                    break;

                case 'A':
                    usable |= KeyCapabilities.Authentication;
                    break;

                case '?':
                    allowed |= KeyCapabilities.Unknown;
                    break;

                case 'D':
                    usable |= KeyCapabilities.Disabled;
                    break;
                }
            }
        }
示例#5
0
  /// <summary>Initializes a new <see cref="NewSubkeyForm"/> with the <see cref="PGPSystem"/> that will be used to
  /// create the subkey.
  /// </summary>
  public void Initialize(PGPSystem pgp)
  {
    if(pgp == null) throw new ArgumentNullException();
    this.pgp = pgp;

    KeyCapabilities signOnly = KeyCapabilities.Sign;
    KeyCapabilities encryptOnly = KeyCapabilities.Encrypt;
    KeyCapabilities signAndEncrypt = signOnly | encryptOnly;

    bool supportsDSA = false, supportsELG = false, supportsRSA = false;
    foreach(string type in pgp.GetSupportedKeyTypes())
    {
      if(!supportsDSA && string.Equals(type, PGP.KeyType.DSA, StringComparison.OrdinalIgnoreCase))
      {
        supportsDSA = true;
      }
      else if(!supportsELG && string.Equals(type, PGP.KeyType.ElGamal, StringComparison.OrdinalIgnoreCase))
      {
        supportsELG = true;
      }
      else if(!supportsRSA && string.Equals(type, PGP.KeyType.RSA, StringComparison.OrdinalIgnoreCase))
      {
        supportsRSA = true;
      }
    }

    keyType.Items.Clear();
    if(supportsELG) keyType.Items.Add(new KeyTypeItem(PGP.KeyType.ElGamal, encryptOnly, "El Gamal (encryption only)"));
    if(supportsRSA) keyType.Items.Add(new KeyTypeItem(PGP.KeyType.RSA, encryptOnly, "RSA (encryption only)"));
    if(supportsDSA) keyType.Items.Add(new KeyTypeItem(PGP.KeyType.DSA, signOnly, "DSA (signing only)"));
    if(supportsRSA)
    {
      keyType.Items.Add(new KeyTypeItem(PGP.KeyType.RSA, signOnly, "RSA (signing only)"));
      keyType.Items.Add(new KeyTypeItem(PGP.KeyType.RSA, signAndEncrypt, "RSA (sign and encrypt)"));
    }
    keyType.SelectedIndex = 0;

    // OpenPGP currently supports a maximum expiration date of February 25, 2174. we'll use the 24th to avoid
    // local <-> UTC conversion problems
    keyExpiration.MinDate = DateTime.Now.Date.AddDays(1);
    keyExpiration.MaxDate = new DateTime(2174, 2, 24, 0, 0, 0, DateTimeKind.Local);
    keyExpiration.Value = DateTime.UtcNow.Date.AddYears(5); // by default, the subkey expires in 5 years
  }
示例#6
0
 /// <summary>Initializes a new <see cref="KeyCollection{T}"/> with the given set of required key capabilities.</summary>
 public KeyCollection(KeyCapabilities requiredCapabilities)
 {
   this.requiredCapabilities = requiredCapabilities;
 }
示例#7
0
 /// <summary>Returns true if the <see cref="Key.Capabilities"/> property contains the given capability flags.</summary>
 public bool HasCapabilities(KeyCapabilities capability)
 {
   return (Capabilities & capability) == capability;
 }
示例#8
0
 /// <summary>
 /// Parses the key capability field from list keys command.
 /// </summary>
 /// <param name="field">The field.</param>
 /// <param name="allowed">The allowed.</param>
 /// <param name="usable">The usable.</param>
 static void ParseKeyCapField(string field, ref KeyCapabilities allowed, ref KeyCapabilities usable)
 {
     foreach (char c in field)
     {
         switch (c)
         {
             case 'e':
                 allowed |= KeyCapabilities.Encrypt;
                 break;
             case 'E':
                 usable |= KeyCapabilities.Encrypt;
                 break;
             case 's':
                 allowed |= KeyCapabilities.Sign;
                 break;
             case 'S':
                 usable |= KeyCapabilities.Sign;
                 break;
             case 'c':
                 allowed |= KeyCapabilities.Certify;
                 break;
             case 'C':
                 usable |= KeyCapabilities.Certify;
                 break;
             case 'a':
                 allowed |= KeyCapabilities.Authentication;
                 break;
             case 'A':
                 usable |= KeyCapabilities.Authentication;
                 break;
             case '?':
                 allowed |= KeyCapabilities.Unknown;
                 break;
             case 'D':
                 usable |= KeyCapabilities.Disabled;
                 break;
         }
     }
 }
示例#9
0
 public KeyTypeItem(string type, KeyCapabilities caps, string text)
   : base(new KeyTypeAndCapability(type, caps), text) { }
示例#10
0
 public KeyTypeAndCapability(string type, KeyCapabilities caps)
 {
   Type         = type;
   Capabilities = caps;
 }