/// <summary> /// Initialise a secure communications connection. /// </summary> /// <param name="request"></param> /// <returns></returns> public Response InitialiseSecureConnection(LoginRequest request) { // Decrypt the password var cp = new CspParameters(); cp.KeyContainerName = "CruiseControl.NET Server"; var provider = new RSACryptoServiceProvider(cp); var originalKey = request.FindCredential(LoginRequest.UserNameCredential).Value; var decryptedKey = UTF8Encoding.UTF8.GetString( provider.Decrypt(Convert.FromBase64String(originalKey), false)); var originalIv = request.FindCredential(LoginRequest.PasswordCredential).Value; var decryptedIv = UTF8Encoding.UTF8.GetString( provider.Decrypt(Convert.FromBase64String(originalIv), false)); // Generate the connection details var connection = new SecureConnection { Expiry = DateTime.Now.AddMinutes(15), IV = Convert.FromBase64String(decryptedIv), Key = Convert.FromBase64String(decryptedKey) }; connections[request.SourceName] = connection; // Generate a response var response = new Response(request); response.Result = ResponseResult.Success; return(response); }
public void FindCredentialHandlesMissingCredential() { var request = new LoginRequest(); request.Credentials = new List <NameValuePair> { new NameValuePair("name", "me") }; var credential = request.FindCredential("password"); Assert.IsNull(credential); }
public Response GenerateConnectioResponse(LoginRequest request, out string iv, out string key) { // Decrypt the password var cp = new CspParameters(); cp.KeyContainerName = "CruiseControl.NET Server"; var provider = new RSACryptoServiceProvider(cp); var originalKey = request.FindCredential(LoginRequest.UserNameCredential).Value; key = UTF8Encoding.UTF8.GetString( provider.Decrypt(Convert.FromBase64String(originalKey), false)); var originalIv = request.FindCredential(LoginRequest.PasswordCredential).Value; iv = UTF8Encoding.UTF8.GetString( provider.Decrypt(Convert.FromBase64String(originalIv), false)); // Generate a response var response = new Response(request); response.Result = ResponseResult.Success; return(response); }
public void FindCredentialFindsExistingCredential() { var request = new LoginRequest(); var password = "******"; request.Credentials = new List <NameValuePair> { new NameValuePair("name", "me"), new NameValuePair("password", password) }; var credential = request.FindCredential("password"); Assert.IsNotNull(credential); Assert.AreEqual(password, credential.Value); }