private CachedKey FetchPublicKeyWithId(string id)
        {
            try
            {
                var cacheKey    = LAUNCHKEY_CACHE_PREFIX + id;
                var keyContents = _publicKeyCache.Get(cacheKey);
                var key         = _crypto.LoadRsaPublicKey(keyContents);
                return(new CachedKey(id, key));
            }
            catch (CacheException) { }    // didn't exist
            catch (CryptographyError) { } // couldnt load it

            try
            {
                // go get it
                var serverResponse = PublicV3PublicKeyGet(id);

                // try to load it
                var key = _crypto.LoadRsaPublicKey(serverResponse.PublicKey);

                // load ok, cache it
                _publicKeyCache.Put(
                    LAUNCHKEY_CACHE_PREFIX + serverResponse.PublicKeyFingerPrint,
                    serverResponse.PublicKey
                    );

                // deliver it
                return(new CachedKey(serverResponse.PublicKeyFingerPrint, key));
            }
            catch (CryptographyError)
            {
                // failed to load it, go get it again
                throw new InvalidResponseException("Server returned an unparseable PEM object while we tried to fetch a key");
            }
        }
Exemple #2
0
 public void Setup()
 {
     _crypto     = new BouncyCastleCrypto();
     _publicKey  = _crypto.LoadRsaPublicKey(File.ReadAllText("test-public.key"));
     _privateKey = _crypto.LoadRsaPrivateKey(File.ReadAllText("test-private.key"));
 }
Exemple #3
0
        public void LoadRsaPublicKey_ShouldThrowOnBadData()
        {
            var pemKey = @"total gibbberish, i mean this doesn't look like a key AT ALL";

            _crypto.LoadRsaPublicKey(pemKey);
        }