示例#1
0
 public SendHandler(ICatalogHandler catalogHandler, IFiksIOSender sender, IAsicEncrypter asicEncrypter, IPublicKeyProvider publicKeyProvider)
 {
     _sender            = sender;
     _asicEncrypter     = asicEncrypter;
     _publicKeyProvider = publicKeyProvider;
     _catalogHandler    = catalogHandler;
 }
示例#2
0
        private async Task RunTest(
            bool signJwt,
            DateTime jwtExpiry,
            Type expectedExceptionType = null
            )
        {
            string             keyId              = Guid.NewGuid().ToString();
            D2LSecurityToken   signingToken       = D2LSecurityTokenUtility.CreateActiveToken(id: keyId);
            SigningCredentials signingCredentials = null;

            if (signJwt)
            {
                signingCredentials = signingToken.GetSigningCredentials();
            }

            var jwtToken = new JwtSecurityToken(
                issuer: "someissuer",
                signingCredentials: signingCredentials,
                expires: jwtExpiry
                );

            var    tokenHandler  = new JwtSecurityTokenHandler();
            string serializedJwt = tokenHandler.WriteToken(jwtToken);

            IPublicKeyProvider publicKeyProvider = PublicKeyProviderMock.Create(
                m_jwksEndpoint,
                keyId,
                signingToken
                ).Object;

            IAccessTokenValidator tokenValidator = new AccessTokenValidator(
                publicKeyProvider
                );

            IAccessToken accessToken = null;
            Exception    exception   = null;

            try {
                accessToken = await tokenValidator.ValidateAsync(
                    accessToken : serializedJwt
                    ).ConfigureAwait(false);
            } catch (Exception e) {
                exception = e;
            }

            if (expectedExceptionType != null)
            {
                Assert.IsNull(accessToken, "Unexpected access token returned from validation");
                Assert.IsNotNull(exception, "Expected an exception but got null");
                Assert.AreEqual(expectedExceptionType, exception.GetType(), "Wrong exception type");
            }
            else
            {
                Assert.IsNotNull(accessToken, "Expected an access token but got none");
            }
        }
		public void BeforeEach() {
			m_jwksProvider = new Mock<IJwksProvider>( MockBehavior.Strict );
			m_keyCache = new Mock<IInMemoryPublicKeyCache>( MockBehavior.Strict );
			KEY_ID = Guid.NewGuid();

			m_publicKeyProvider = new RemotePublicKeyProvider(
				m_jwksProvider.Object,
				m_keyCache.Object
			);
		}
示例#4
0
 public KeyVaultCache(
     IPublicKeyProvider publicKeyProvider,
     IOptions <AzureKeyVaultTokenSigningServiceOptions> keyVaultOptions,
     IMemoryCache cache,
     ILogger <KeyVaultCache> logger)
 {
     _publicKeyProvider           = publicKeyProvider;
     _keyVaultOptions             = keyVaultOptions.Value;
     _azureKeyVaultAuthentication = new AzureKeyVaultAuthentication(_keyVaultOptions.ClientId, _keyVaultOptions.ClientSecret);
     _cache          = cache;
     _logger         = logger;
     _cachedData     = new DefaultCache <CacheData>(_cache);
     _cacheTimeStamp = new DefaultCache <TimeStamp>(_cache);
 }
示例#5
0
 public MyDefaultTokenCreationService(
     IKeyVaultCache keyVaultCache,
     ISystemClock clock,
     IKeyMaterialService keys,
     IPublicKeyProvider publicKeyProvider,
     IMemoryCache cache,
     IOptions <AzureKeyVaultTokenSigningServiceOptions> keyVaultOptions,
     ILogger <DefaultTokenCreationService> logger) : base(clock, keys, logger)
 {
     _keyVaultCache     = keyVaultCache;
     _cache             = cache;
     _publicKeyProvider = publicKeyProvider;
     _keyVaultOptions   = keyVaultOptions;
 }
        public string Encrypt(string plainTextMessage, IPublicKeyProvider publicKeyProvider)
        {
            var publicKey = AsymetricKeyParameterExtensions
                            .GetPublicKeyFromString(publicKeyProvider
                                                    .GetPublicKeyString(folderProvider.GetFolderName()));

            var csp = new RSACryptoServiceProvider(2048);

            csp.ImportParameters(publicKey);

            var bytesPlainText  = Encoding.Unicode.GetBytes(plainTextMessage);
            var bytesCipherText = csp.Encrypt(bytesPlainText, false);

            return(Convert.ToBase64String(bytesCipherText));
        }
		public void BeforeEach() {
			m_jwksProvider = new Mock<IJwksProvider>( MockBehavior.Strict );
			m_keyCache = new Mock<IInMemoryPublicKeyCache>( MockBehavior.Strict );
            SRC_NAMESPACE = Guid.NewGuid().ToString();
			KEY_ID = Guid.NewGuid();

            m_jwksProvider
                .Setup( x => x.Namespace )
                .Returns( SRC_NAMESPACE );

            m_publicKeyProvider = new RemotePublicKeyProvider(
				m_jwksProvider.Object,
				m_keyCache.Object
			);
		}
示例#8
0
 public SendHandler(
     ICatalogHandler catalogHandler,
     IMaskinportenClient maskinportenClient,
     FiksIOSenderConfiguration senderConfiguration,
     IntegrasjonConfiguration integrasjonConfiguration,
     HttpClient httpClient,
     IAsicEncrypter asicEncrypter,
     IPublicKeyProvider publicKeyProvider)
     : this(
         catalogHandler,
         new FiksIOSender(senderConfiguration, maskinportenClient, integrasjonConfiguration.IntegrasjonId, integrasjonConfiguration.IntegrasjonPassord, httpClient),
         asicEncrypter,
         publicKeyProvider)
 {
 }
 public MyDefaultTokenCreationService(
     IKeyVaultCache keyVaultCache,
     ISystemClock clock,
     IKeyMaterialService keys,
     IPublicKeyProvider publicKeyProvider,
     IMemoryCache cache,
     IOptions <AzureKeyVaultTokenSigningServiceOptions> keyVaultOptions,
     ILogger <DefaultTokenCreationService> logger) : base(clock, keys, logger)
 {
     _keyVaultCache     = keyVaultCache;
     _cache             = cache;
     _publicKeyProvider = publicKeyProvider;
     _keyVaultOptions   = keyVaultOptions;
     _signitureProvider = new ExpirableObjectCache <AzureKeyVaultSignatureProvider>(new TimeSpan(0, 0, 5, 0), Refresher);
 }
示例#10
0
        internal FiksIOClient(
            FiksIOConfiguration configuration,
            ICatalogHandler catalogHandler         = null,
            IMaskinportenClient maskinportenClient = null,
            ISendHandler sendHandler = null,
            IDokumentlagerHandler dokumentlagerHandler = null,
            IAmqpHandler amqpHandler             = null,
            HttpClient httpClient                = null,
            IPublicKeyProvider publicKeyProvider = null)
        {
            KontoId = configuration.KontoConfiguration.KontoId;

            maskinportenClient = maskinportenClient ?? new MaskinportenClient(configuration.MaskinportenConfiguration, httpClient);

            _catalogHandler = catalogHandler ?? new CatalogHandler(
                configuration.KatalogConfiguration,
                configuration.IntegrasjonConfiguration,
                maskinportenClient,
                httpClient);

            _publicKeyProvider = publicKeyProvider ?? new CatalogPublicKeyProvider(_catalogHandler);

            var asicEncrypter = new AsicEncrypter(new AsiceBuilderFactory(), new EncryptionServiceFactory());

            _sendHandler = sendHandler ??
                           new SendHandler(
                _catalogHandler,
                maskinportenClient,
                configuration.FiksIOSenderConfiguration,
                configuration.IntegrasjonConfiguration,
                httpClient,
                asicEncrypter,
                _publicKeyProvider);

            _dokumentlagerHandler = dokumentlagerHandler ?? new DokumentlagerHandler(
                configuration.DokumentlagerConfiguration,
                configuration.IntegrasjonConfiguration,
                maskinportenClient,
                httpClient: httpClient);

            _amqpHandler = amqpHandler ?? new AmqpHandler(
                maskinportenClient,
                _sendHandler,
                _dokumentlagerHandler,
                configuration.AmqpConfiguration,
                configuration.IntegrasjonConfiguration,
                configuration.KontoConfiguration);
        }
示例#11
0
        public void BeforeEach()
        {
            m_jwksProvider = new Mock <IJwksProvider>(MockBehavior.Strict);
            m_keyCache     = new Mock <IInMemoryPublicKeyCache>(MockBehavior.Strict);
            SRC_NAMESPACE  = Guid.NewGuid().ToString();
            KEY_ID         = Guid.NewGuid();

            m_jwksProvider
            .Setup(x => x.Namespace)
            .Returns(SRC_NAMESPACE);

            m_publicKeyProvider = new RemotePublicKeyProvider(
                m_jwksProvider.Object,
                m_keyCache.Object
                );
        }
示例#12
0
 public AccessTokenValidator(
     IPublicKeyProvider publicKeyProvider
     )
 {
     m_publicKeyProvider = publicKeyProvider;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="AzureKeyVaultTokenSigningService"/> class.
 /// </summary>
 /// <param name="publicKeyProvider">The public key provider.</param>
 /// <param name="options">The options.</param>
 public AzureKeyVaultTokenSigningService(IPublicKeyProvider publicKeyProvider, IOptions <AzureKeyVaultTokenSigningServiceOptions> options)
 {
     _publicKeyProvider = publicKeyProvider;
     _options           = options.Value;
     _authentication    = new AzureKeyVaultAuthentication(_options.ClientId, _options.ClientSecret);
 }
示例#14
0
 public SigningKeyService(IPublicKeyProvider publicKeyProvider)
 {
     mPublicKeyProvider = publicKeyProvider;
 }
示例#15
0
 public FiksIOClient(FiksIOConfiguration configuration, HttpClient httpClient = null, IPublicKeyProvider publicKeyProvider = null)
     : this(configuration, null, null, null, null, null, httpClient, publicKeyProvider)
 {
 }
		public AccessTokenValidator(
			IPublicKeyProvider publicKeyProvider
		) {
			m_publicKeyProvider = publicKeyProvider;
		}
 /// <summary>
 /// Initializes a new instance of the <see cref="AzureKeyVaultTokenSigningService"/> class.
 /// </summary>
 /// <param name="publicKeyProvider">The public key provider.</param>
 /// <param name="options">The options.</param>
 public AzureKeyVaultTokenSigningService(IPublicKeyProvider publicKeyProvider, IOptions<AzureKeyVaultTokenSigningServiceOptions> options)
 {
     _publicKeyProvider = publicKeyProvider;
     _options = options.Value;
     _authentication = new AzureKeyVaultAuthentication(_options.ClientId, _options.ClientSecret);
 }