public void StoreKey(string bucket, string handle, CryptoKey key)
        {
            var keyRow = new SymmetricCryptoKey { Bucket = bucket, Handle = handle, Secret = key.Key, ExpiresUtc = key.ExpiresUtc, };

            this.db.SymmetricCryptoKeys.Add(keyRow);
            this.db.SaveChanges();
        }
 public void StoreKey(string bucket, string handle, CryptoKey key)
 {
     var entry = new CryptoKeyStoreEntry();
     entry.Bucket = bucket;
     entry.Handle = handle;
     entry.Key = key;
     keys.Add(entry);
 }
		public void StoreKey(string bucket, string handle, CryptoKey key) {
			var keyRow = new SymmetricCryptoKey() {
				Bucket = bucket,
				Handle = handle,
				Secret = key.Key,
				ExpiresUtc = key.ExpiresUtc,
			};

			WebApiApplication.DataContext.SymmetricCryptoKeys.InsertOnSubmit(keyRow);
			WebApiApplication.DataContext.SubmitChanges();
		}
		public void StoreKey(string bucket, string handle, CryptoKey key) {
			using (var dataContext = new TransactedDatabaseEntities(System.Data.IsolationLevel.ReadCommitted)) {
				var sharedAssociation = new SymmetricCryptoKey {
					Bucket = bucket,
					Handle = handle,
					ExpirationUtc = key.ExpiresUtc,
					Secret = key.Key,
				};

				dataContext.AddToSymmetricCryptoKeys(sharedAssociation);
			}
		}
Ejemplo n.º 5
0
        public void StoreKey(string bucket, string handle, CryptoKey key)
        {
            var keyRow = new SymmetricCryptoKey() {
                Bucket = bucket,
                Handle = handle,
                Secret = key.Key,
                ExpiresUtc = key.ExpiresUtc,
            };

            MvcApplication.DataContext.AddToSymmetricCryptoKeys(keyRow);
            MvcApplication.DataContext.SaveChanges();
        }
Ejemplo n.º 6
0
 public void StoreKey(string bucket, string handle, CryptoKey key)
 {
     var keyRow = new oauth_symmetriccryptokey()
     {
         Bucket = bucket,
         Handle = handle,
         Secret = key.Key,
         ExpiresUtc = key.ExpiresUtc,
     };
     var db = new OAuthEntities();
     db.oauth_symmetriccryptokey.AddObject(keyRow);
     db.SaveChanges();
 }
Ejemplo n.º 7
0
		/// <summary>
		/// Stores a cryptographic key.
		/// </summary>
		/// <param name="bucket">The name of the bucket to store the key in.  Case sensitive.</param>
		/// <param name="handle">The handle to the key, unique within the bucket.  Case sensitive.</param>
		/// <param name="key">The key to store.</param>
		/// <exception cref="CryptoKeyCollisionException">Thrown in the event of a conflict with an existing key in the same bucket and with the same handle.</exception>
		public void StoreKey(string bucket, string handle, CryptoKey key) {
			lock (this.store) {
				Dictionary<string, CryptoKey> cacheBucket;
				if (!this.store.TryGetValue(bucket, out cacheBucket)) {
					this.store[bucket] = cacheBucket = new Dictionary<string, CryptoKey>(StringComparer.Ordinal);
				}

				if (cacheBucket.ContainsKey(handle)) {
					throw new CryptoKeyCollisionException();
				}

				cacheBucket[handle] = key;

				this.CleanExpiredKeysFromMemoryCacheIfAppropriate();
			}
		}
Ejemplo n.º 8
0
        public CryptoKey GetKey(string bucket, string handle)
        {
            // It is critical that this lookup be case-sensitive, which can only be configured at the database.
            List<CryptoKey> keys = new List<CryptoKey>();

            var ms = from key in MvcApplication.DataContext.SymmetricCryptoKeys
                     where key.Bucket == bucket && key.Handle == handle
                     select key;

            foreach (var m in ms)
            {
                CryptoKey ck = new CryptoKey(m.Secret, m.ExpiresUtc.AsUtc());
                keys.Add(ck);
            }

            return keys.FirstOrDefault();
        }
Ejemplo n.º 9
0
		/// <summary>
		/// Stores a cryptographic key.
		/// </summary>
		/// <param name="bucket">The name of the bucket to store the key in.  Case sensitive.</param>
		/// <param name="handle">The handle to the key, unique within the bucket.  Case sensitive.</param>
		/// <param name="key">The key to store.</param>
		/// <exception cref="CryptoKeyCollisionException">Thrown in the event of a conflict with an existing key in the same bucket and with the same handle.</exception>
		void ICryptoKeyStore.StoreKey(string bucket, string handle, CryptoKey key) {
			Contract.Requires<ArgumentException>(!String.IsNullOrEmpty(bucket));
			Contract.Requires<ArgumentException>(!String.IsNullOrEmpty(handle));
			Contract.Requires<ArgumentNullException>(key != null);
			throw new NotImplementedException();
		}
Ejemplo n.º 10
0
		/// <summary>
		/// Stores a cryptographic key.
		/// </summary>
		/// <param name="bucket">The name of the bucket to store the key in.  Case sensitive.</param>
		/// <param name="handle">The handle to the key, unique within the bucket.  Case sensitive.</param>
		/// <param name="key">The key to store.</param>
		/// <exception cref="CryptoKeyCollisionException">Thrown in the event of a conflict with an existing key in the same bucket and with the same handle.</exception>
		void ICryptoKeyStore.StoreKey(string bucket, string handle, CryptoKey key) {
			Requires.NotNullOrEmpty(bucket, "bucket");
			Requires.NotNullOrEmpty(handle, "handle");
			Requires.NotNull(key, "key");
			throw new NotImplementedException();
		}
Ejemplo n.º 11
0
        public void StoreKey(string bucket, string handle, CryptoKey key) {
            Keys.Add(new SymmetricCryptoKey(bucket, handle, key.Key, key.ExpiresUtc));

        }
		/// <summary>
		/// Stores a cryptographic key.
		/// </summary>
		/// <param name="bucket">The name of the bucket to store the key in.  Case sensitive.</param>
		/// <param name="handle">The handle to the key, unique within the bucket.  Case sensitive.</param>
		/// <param name="key">The key to store.</param>
		/// <exception cref="System.NotSupportedException">Always thrown.</exception>
		public void StoreKey(string bucket, string handle, CryptoKey key) {
			throw new NotSupportedException();
		}
		/// <summary>
		/// Initializes a new instance of the <see cref="HardCodedKeyCryptoKeyStore"/> class.
		/// </summary>
		/// <param name="secret">The 256-bit secret.</param>
		public HardCodedKeyCryptoKeyStore(byte[] secret) {
			Requires.NotNull(secret, "secret");
			this.OneCryptoKey = new CryptoKey(secret, DateTime.MaxValue.AddDays(-2).ToUniversalTime());
		}
Ejemplo n.º 14
0
 public void StoreKey(string bucket, string handle, CryptoKey key)
 {
     this.authorizationStoreAgent.StoreKey(bucket, handle, key);
 }
		/// <summary>
		/// Saves an <see cref="Association"/> for later recall.
		/// </summary>
		/// <param name="providerEndpoint">The OP Endpoint with which the association is established.</param>
		/// <param name="association">The association to store.</param>
		public void StoreAssociation(Uri providerEndpoint, Association association) {
			var cryptoKey = new CryptoKey(association.SerializePrivateData(), association.Expires);
			this.keyStore.StoreKey(providerEndpoint.AbsoluteUri, association.Handle, cryptoKey);
		}
		/// <summary>
		/// Stores a cryptographic key.
		/// </summary>
		/// <param name="bucket">The name of the bucket to store the key in.  Case sensitive.</param>
		/// <param name="handle">The handle to the key, unique within the bucket.  Case sensitive.</param>
		/// <param name="key">The key to store.</param>
		/// <exception cref="CryptoKeyCollisionException">Thrown in the event of a conflict with an existing key in the same bucket and with the same handle.</exception>
		public void StoreKey(string bucket, string handle, CryptoKey key) {
			this.cryptoKeyStore.StoreKey(bucket, handle, key);
		}
Ejemplo n.º 17
0
		public void StoreKey(string bucket, string handle, CryptoKey key) {
			var cryptoKeyRow = dataSet.CryptoKey.NewCryptoKeyRow();
			cryptoKeyRow.Bucket = bucket;
			cryptoKeyRow.Handle = handle;
			cryptoKeyRow.ExpiresUtc = key.ExpiresUtc;
			cryptoKeyRow.Secret = key.Key;
			dataSet.CryptoKey.AddCryptoKeyRow(cryptoKeyRow);
		}
Ejemplo n.º 18
0
 /// <summary>
 /// Initializes a new instance of the <see cref="HardCodedKeyCryptoKeyStore"/> class.
 /// </summary>
 /// <param name="secret">The 256-bit secret.</param>
 public HardCodedKeyCryptoKeyStore(byte[] secret)
 {
     this.OneCryptoKey = new CryptoKey(secret, DateTime.MaxValue.AddDays(-2).ToUniversalTime());
 }