public void TestGetFileCredentialsAsMapService1() { // store and clear user set env variable string ibmCredFile = Environment.GetEnvironmentVariable("IBM_CREDENTIALS_FILE"); Environment.SetEnvironmentVariable("IBM_CREDENTIALS_FILE", ""); // create .env file in current directory string[] linesWorking = { "SERVICE_1_AUTH_TYPE=iam", "SERVICE_1_APIKEY=V4HXmoUtMjohnsnow=KotN", "SERVICE_1_CLIENT_ID=somefake========id", "SERVICE_1_CLIENT_SECRET===my-client-secret==", "SERVICE_1_AUTH_URL=https://iamhost/iam/api=", "SERVICE_1_AUTH_DISABLE_SSL=" }; var directoryPath = Directory.GetCurrentDirectory(); var credsFile = Path.Combine(directoryPath, "ibm-credentials.env"); using (StreamWriter outputFile = new StreamWriter(credsFile)) { foreach (string line in linesWorking) { outputFile.WriteLine(line); } } // get props Dictionary <string, string> propsWorking = CredentialUtils.GetFileCredentialsAsMap("service_1"); Assert.IsNotNull(propsWorking); Assert.AreEqual(propsWorking["AUTH_TYPE"], "iam"); Assert.AreEqual(propsWorking["APIKEY"], "V4HXmoUtMjohnsnow=KotN"); Assert.AreEqual(propsWorking["CLIENT_ID"], "somefake========id"); Assert.AreEqual(propsWorking["CLIENT_SECRET"], "==my-client-secret=="); Assert.AreEqual(propsWorking["AUTH_URL"], "https://iamhost/iam/api="); Assert.IsFalse(propsWorking.ContainsKey("DISABLE_SSL")); // delete created env files if (File.Exists(credsFile)) { File.Delete(credsFile); } // reset env variable Environment.SetEnvironmentVariable("IBM_CREDENTIALS_FILE", ibmCredFile); }
private Stream getRssQueryResultStream(StringBuilder url) { HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url.ToString()); req.Proxy = server.NoProxy ? null : GlobalSettings.Proxy; req.Credentials = CredentialUtils.getCredentialsForUserAndPassword(url.ToString(), UserName, Password); req.Timeout = GlobalSettings.NetworkTimeout * 1000; req.ReadWriteTimeout = GlobalSettings.NetworkTimeout * 2000; req.UserAgent = Constants.USER_AGENT; if (!server.OldSkoolAuth) { setSessionCookie(req); } HttpWebResponse resp = (HttpWebResponse)req.GetResponse(); return(resp.GetResponseStream()); }
private void treeJira_AfterSelect(object sender, TreeViewEventArgs e) { AbstractNavigableTreeNodeWithServer node = treeJira.SelectedNode as AbstractNavigableTreeNodeWithServer; dropDownActions.DropDownItems.Add("phony"); if (node != null) { node.onClick(status); string url = node.getUrl(CredentialUtils.getOsAuthString(server)); webJira.Browser.Navigate(url); ICollection <ToolStripItem> menuItems = node.MenuItems; dropDownActions.Enabled = menuItems != null && menuItems.Count > 0; } else { dropDownActions.Enabled = false; } }
private static HttpWebResponse getResponse(Server server, string url) { string authUrl = server == null ? url : url + "?" + CredentialUtils.getOsAuthString(server); HttpWebRequest request = (HttpWebRequest)WebRequest.Create(authUrl); request.KeepAlive = true; if (server != null) { request.Credentials = CredentialUtils.getCredentialsForUserAndPassword(url, server.UserName, server.Password); } request.Accept = @"image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, */*"; HttpWebResponse response = (HttpWebResponse)request.GetResponse(); return(response); }
public IDictionary<string, string> login() { HttpWebRequest req = (HttpWebRequest)WebRequest.Create(BaseUrl + "/Dashboard.jspa"); req.Proxy = dontUseProxy ? null : GlobalSettings.Proxy; req.Credentials = CredentialUtils.getCredentialsForUserAndPassword(BaseUrl, UserName, Password); req.Timeout = GlobalSettings.NetworkTimeout * 1000; req.ReadWriteTimeout = GlobalSettings.NetworkTimeout * 2000; req.Method = "POST"; req.ContentType = "application/x-www-form-urlencoded"; string pars = getLoginPostData(UserName, Password); req.ContentLength = pars.Length; using (StreamWriter outStream = new StreamWriter(req.GetRequestStream(), Encoding.ASCII)) { outStream.Write(pars); outStream.Flush(); outStream.Close(); HttpWebResponse resp = (HttpWebResponse)req.GetResponse(); using (resp.GetResponseStream()) { if (!resp.StatusCode.Equals(HttpStatusCode.OK)) { throw new LoginException(new Exception(resp.StatusDescription)); } string cookies = resp.Headers["Set-Cookie"]; if (cookies == null) { throw new LoginException(new Exception(NO_SESSION_COOKIE)); } string jSessionId = getSessionToken(cookies, JSESSIONID); string studioCrowdToken = getSessionToken(cookies, STUDIO_CROWD_TOKEN); if (jSessionId == null && studioCrowdToken == null) { throw new LoginException(new Exception(NO_SESSION_COOKIE)); } Dictionary<string, string> tokens = new Dictionary<string, string>(); if (jSessionId != null) { tokens[JSESSIONID] = jSessionId; } if (studioCrowdToken != null) { tokens[STUDIO_CROWD_TOKEN] = studioCrowdToken; } SessionTokens = tokens; return SessionTokens; } } }
public void Setup() { var creds = CredentialUtils.GetServiceProperties("assistant"); creds.TryGetValue("WORKSPACE_ID", out workspaceId); service = new AssistantService(versionDate); #if DELETE_DOTNET_WORKSPACES service.WithHeader("X-Watson-Test", "1"); var workspaces = service.ListWorkspaces(); List <string> dotnet_workpaces = new List <string>(); foreach (Workspace workspace in workspaces.Workspaces) { if (workspace.Name == createdWorkspaceName) { dotnet_workpaces.Add(workspace.WorkspaceId); } } foreach (string workspaceId in dotnet_workpaces) { try { var getWorkspaceResult = GetWorkspace( workspaceId: workspaceId ); if (getWorkspaceResult != null) { DeleteWorkspace( workspaceId: workspaceId ); } } catch (Exception e) { Console.WriteLine("error: {0}", e.Message); } } #endif }
public void TestHasBadStartOrEndChar() { var bracketBegin = "{value"; var bracketEnd = "value}"; var quoteBegin = "\"value"; var quoteEnd = "value\""; var goodValue = "value"; var testBracketBegin = CredentialUtils.HasBadStartOrEndChar(bracketBegin); var testBracketEnd = CredentialUtils.HasBadStartOrEndChar(bracketEnd); var testQuoteBegin = CredentialUtils.HasBadStartOrEndChar(quoteBegin); var testQuoteEnd = CredentialUtils.HasBadStartOrEndChar(quoteEnd); var testGoodValue = CredentialUtils.HasBadStartOrEndChar(goodValue); Assert.IsTrue(testBracketBegin); Assert.IsTrue(testBracketEnd); Assert.IsTrue(testQuoteBegin); Assert.IsTrue(testQuoteEnd); Assert.IsFalse(testGoodValue); }
public void TestGetVcapCredentialsAsMapVcapNotSet() { var tempVcapCredential = new Dictionary <string, List <VcapCredential> >(); //create credential entries for first service entry var vcapCredential = new VcapCredential() { Credentials = new Credential() { ApiKey = "assistantV1apikey" } }; vcapCredential.Name = "assistantV1"; tempVcapCredential.Add("assistant", new List <VcapCredential>() { vcapCredential }); var vcapCredentaialsAsMap = CredentialUtils.GetVcapCredentialsAsMap("fake_entry"); // Assert.IsNotNull(vcapCredentaialsAsMap); // Assert.IsTrue(vcapCredentaialsAsMap.Count == 0); }
public override void Validate() { if (string.IsNullOrEmpty(Username)) { throw new ArgumentNullException(string.Format(ErrorMessagePropMissing, "Username")); } if (string.IsNullOrEmpty(Password)) { throw new ArgumentNullException(string.Format(ErrorMessagePropMissing, "Password")); } if (CredentialUtils.HasBadStartOrEndChar(Username)) { throw new ArgumentException(string.Format(ErrorMessagePropInvalid, "Username")); } if (CredentialUtils.HasBadStartOrEndChar(Password)) { throw new ArgumentException(string.Format(ErrorMessagePropInvalid, "Password")); } }
public override void Validate() { if (string.IsNullOrEmpty(Apikey)) { throw new ArgumentNullException(string.Format(ErrorMessagePropMissing, "apikey")); } if (CredentialUtils.HasBadStartOrEndChar(Apikey)) { throw new ArgumentException(string.Format(ErrorMessagePropInvalid, "apikey")); } if (CredentialUtils.HasBadStartOrEndChar(Url)) { throw new ArgumentException(string.Format(ErrorMessagePropInvalid, "url")); } if (Utility.OnlyOne(ClientId, ClientSecret)) { Console.WriteLine("Warning: Client ID and Secret must BOTH be given, or the defaults will be used."); } }
public void TestGetVcapCredentialsAsMapNoCreds() { var tempVcapCredential = new Dictionary <string, List <VcapCredential> >(); //create credential entries for first service entry var vcapCredential = new VcapCredential() { }; vcapCredential.Name = "assistantV1"; tempVcapCredential.Add("assistant", new List <VcapCredential>() { vcapCredential }); var vcapString = JsonConvert.SerializeObject(tempVcapCredential); Environment.SetEnvironmentVariable("VCAP_SERVICES", vcapString); //Assert.IsNotNull(Environment.GetEnvironmentVariable("VCAP_SERVICES")); var vcapCredentaialsAsMap = CredentialUtils.GetVcapCredentialsAsMap("no-creds"); // Assert.IsNotNull(vcapCredentaialsAsMap); // Assert.IsTrue(vcapCredentaialsAsMap.Count == 0); }
protected string appendAuthentication(string url) { if (UserName != null) { return (url.Contains("?") ? "&" : "?") + CredentialUtils.getOsAuthString(UserName, Password); } return ""; }
CreateOfferAsync(IAgentContext agentContext, OfferConfiguration config, string connectionId = null) { Logger.LogInformation(LoggingEvents.CreateCredentialOffer, "DefinitionId {0}, IssuerDid {1}", config.CredentialDefinitionId, config.IssuerDid); var threadId = Guid.NewGuid().ToString(); if (!string.IsNullOrEmpty(connectionId)) { var connection = await ConnectionService.GetAsync(agentContext, connectionId); if (connection.State != ConnectionState.Connected) { throw new AgentFrameworkException(ErrorCode.RecordInInvalidState, $"Connection state was invalid. Expected '{ConnectionState.Connected}', found '{connection.State}'"); } } if (config.CredentialAttributeValues != null && config.CredentialAttributeValues.Any()) { CredentialUtils.ValidateCredentialPreviewAttributes(config.CredentialAttributeValues); } var offerJson = await AnonCreds.IssuerCreateCredentialOfferAsync( agentContext.Wallet, config.CredentialDefinitionId); var offerJobj = JObject.Parse(offerJson); var schemaId = offerJobj["schema_id"].ToObject <string>(); // Write offer record to local wallet var credentialRecord = new CredentialRecord { Id = Guid.NewGuid().ToString(), CredentialDefinitionId = config.CredentialDefinitionId, OfferJson = offerJson, ConnectionId = connectionId, SchemaId = schemaId, CredentialAttributesValues = config.CredentialAttributeValues, State = CredentialState.Offered, }; credentialRecord.SetTag(TagConstants.LastThreadId, threadId); credentialRecord.SetTag(TagConstants.Role, TagConstants.Issuer); if (!string.IsNullOrEmpty(config.IssuerDid)) { credentialRecord.SetTag(TagConstants.IssuerDid, config.IssuerDid); } if (config.Tags != null) { foreach (var tag in config.Tags) { if (!credentialRecord.Tags.Keys.Contains(tag.Key)) { credentialRecord.Tags.Add(tag.Key, tag.Value); } } } await RecordService.AddAsync(agentContext.Wallet, credentialRecord); return(new CredentialOfferMessage { Id = threadId, OfferJson = offerJson, Preview = credentialRecord.CredentialAttributesValues != null ? new CredentialPreviewMessage { Attributes = credentialRecord.CredentialAttributesValues } : null }, credentialRecord); }
private void removeSoapSessionToken(JiraServer server) { lock (soapTokenMap) { soapTokenMap.Remove(CredentialUtils.getSessionOrTokenKey(server)); } }
public void CanValidateCredentialAttribute() { var attributeValue = new CredentialPreviewAttribute("first_name", "Test"); CredentialUtils.ValidateCredentialPreviewAttribute(attributeValue); }
public void TestGetFileCredentialsAsMap() { var fileCredentialsAsMap = CredentialUtils.GetFileCredentialsAsMap("assistant"); Assert.IsNotNull(fileCredentialsAsMap); }
public void TestFixtureSetup() { client = new DirectConnectionClient(CredentialUtils.GetTestCredentials(), true); }
/// <inheritdoc /> public async Task <(CredentialOfferMessage, CredentialRecord)> CreateOfferAsync( IAgentContext agentContext, OfferConfiguration config, string connectionId) { Logger.LogInformation(LoggingEvents.CreateCredentialOffer, "DefinitionId {0}, IssuerDid {1}", config.CredentialDefinitionId, config.IssuerDid); var threadId = Guid.NewGuid().ToString(); if (!string.IsNullOrEmpty(connectionId)) { var connection = await ConnectionService.GetAsync(agentContext, connectionId); if (connection.State != ConnectionState.Connected) { throw new AriesFrameworkException(ErrorCode.RecordInInvalidState, $"Connection state was invalid. Expected '{ConnectionState.Connected}', found '{connection.State}'"); } } if (config.CredentialAttributeValues != null && config.CredentialAttributeValues.Any()) { CredentialUtils.ValidateCredentialPreviewAttributes(config.CredentialAttributeValues); } var offerJson = await AnonCreds.IssuerCreateCredentialOfferAsync( agentContext.Wallet, config.CredentialDefinitionId); var offerJobj = JObject.Parse(offerJson); var schemaId = offerJobj["schema_id"].ToObject <string>(); // Write offer record to local wallet var credentialRecord = new CredentialRecord { Id = threadId, CredentialDefinitionId = config.CredentialDefinitionId, OfferJson = offerJson, ConnectionId = connectionId, SchemaId = schemaId, CredentialAttributesValues = config.CredentialAttributeValues, State = CredentialState.Offered, }; credentialRecord.SetTag(TagConstants.LastThreadId, threadId); credentialRecord.SetTag(TagConstants.Role, TagConstants.Issuer); if (!string.IsNullOrEmpty(config.IssuerDid)) { credentialRecord.SetTag(TagConstants.IssuerDid, config.IssuerDid); } if (config.Tags != null) { foreach (var tag in config.Tags) { if (!credentialRecord.Tags.Keys.Contains(tag.Key)) { credentialRecord.Tags.Add(tag.Key, tag.Value); } } } await RecordService.AddAsync(agentContext.Wallet, credentialRecord); return(new CredentialOfferMessage(agentContext.UseMessageTypesHttps) { Id = threadId, Offers = new Attachment[] { new Attachment { Id = "libindy-cred-offer-0", MimeType = CredentialMimeTypes.ApplicationJsonMimeType, Data = new AttachmentContent { Base64 = offerJson.GetUTF8Bytes().ToBase64String() } } }, CredentialPreview = credentialRecord.CredentialAttributesValues != null ? new CredentialPreviewMessage(agentContext.UseMessageTypesHttps) { Attributes = credentialRecord.CredentialAttributesValues.Select(x => new CredentialPreviewAttribute { Name = x.Name, MimeType = x.MimeType, Value = x.Value?.ToString() }).ToArray() } : null }, credentialRecord); }
public async Task <(CredentialIssueMessage, CredentialRecord)> CreateCredentialAsync(IAgentContext agentContext, string credentialId, IEnumerable <CredentialPreviewAttribute> values) { var credential = await GetAsync(agentContext, credentialId); if (credential.State != CredentialState.Requested) { throw new AgentFrameworkException(ErrorCode.RecordInInvalidState, $"Credential state was invalid. Expected '{CredentialState.Requested}', found '{credential.State}'"); } if (values != null && values.Any()) { credential.CredentialAttributesValues = values; } var definitionRecord = await SchemaService.GetCredentialDefinitionAsync(agentContext.Wallet, credential.CredentialDefinitionId); var connection = await ConnectionService.GetAsync(agentContext, credential.ConnectionId); var provisioning = await ProvisioningService.GetProvisioningAsync(agentContext.Wallet); if (connection.State != ConnectionState.Connected) { throw new AgentFrameworkException(ErrorCode.RecordInInvalidState, $"Connection state was invalid. Expected '{ConnectionState.Connected}', found '{connection.State}'"); } string revocationRegistryId = null; BlobStorageReader tailsReader = null; if (definitionRecord.SupportsRevocation) { var revocationRecordSearch = await RecordService.SearchAsync <RevocationRegistryRecord>( agentContext.Wallet, SearchQuery.Equal(nameof(RevocationRegistryRecord.CredentialDefinitionId), definitionRecord.Id), null, 5); var revocationRecord = revocationRecordSearch.Single(); // TODO: Credential definition can have multiple revocation registries revocationRegistryId = revocationRecord.Id; tailsReader = await TailsService.OpenTailsAsync(revocationRecord.TailsFile); } var issuedCredential = await AnonCreds.IssuerCreateCredentialAsync(agentContext.Wallet, credential.OfferJson, credential.RequestJson, CredentialUtils.FormatCredentialValues(credential.CredentialAttributesValues), revocationRegistryId, tailsReader); if (definitionRecord.SupportsRevocation) { var paymentInfo = await PaymentService.GetTransactionCostAsync(agentContext, TransactionTypes.REVOC_REG_ENTRY); await LedgerService.SendRevocationRegistryEntryAsync( wallet : agentContext.Wallet, pool : await agentContext.Pool, issuerDid : provisioning.IssuerDid, revocationRegistryDefinitionId : revocationRegistryId, revocationDefinitionType : "CL_ACCUM", value : issuedCredential.RevocRegDeltaJson, paymentInfo : paymentInfo); credential.CredentialRevocationId = issuedCredential.RevocId; if (paymentInfo != null) { await RecordService.UpdateAsync(agentContext.Wallet, paymentInfo.PaymentAddress); } } await credential.TriggerAsync(CredentialTrigger.Issue); await RecordService.UpdateAsync(agentContext.Wallet, credential); var threadId = credential.GetTag(TagConstants.LastThreadId); var credentialMsg = new CredentialIssueMessage { Credentials = new [] { new Attachment { Id = "libindy-cred-0", MimeType = CredentialMimeTypes.ApplicationJsonMimeType, Data = new AttachmentContent { Base64 = issuedCredential.CredentialJson .GetUTF8Bytes() .ToBase64String() } } } }; credentialMsg.ThreadFrom(threadId); return(credentialMsg, credential); }
/// <inheritdoc /> public virtual async Task IssueCredentialAsync(IAgentContext agentContext, string issuerDid, string credentialId, Dictionary <string, string> values) { var credential = await GetAsync(agentContext, credentialId); if (credential.State != CredentialState.Requested) { throw new AgentFrameworkException(ErrorCode.RecordInInvalidState, $"Credential state was invalid. Expected '{CredentialState.Requested}', found '{credential.State}'"); } var credentialCopy = credential.DeepCopy(); if (values != null && values.Count > 0) { credential.ValuesJson = CredentialUtils.FormatCredentialValues(values); } var definitionRecord = await SchemaService.GetCredentialDefinitionAsync(agentContext.Wallet, credential.CredentialDefinitionId); var connection = await ConnectionService.GetAsync(agentContext, credential.ConnectionId); if (connection.State != ConnectionState.Connected) { throw new AgentFrameworkException(ErrorCode.RecordInInvalidState, $"Connection state was invalid. Expected '{ConnectionState.Connected}', found '{connection.State}'"); } string revocationRegistryId = null; BlobStorageReader tailsReader = null; if (definitionRecord.SupportsRevocation) { var revocationRecordSearch = await RecordService.SearchAsync <RevocationRegistryRecord>( agentContext.Wallet, SearchQuery.Equal(nameof(RevocationRegistryRecord.CredentialDefinitionId), definitionRecord.Id), null, 5); var revocationRecord = revocationRecordSearch.Single(); // TODO: Credential definition can have multiple revocation registries revocationRegistryId = revocationRecord.Id; tailsReader = await TailsService.OpenTailsAsync(revocationRecord.TailsFile); } var issuedCredential = await AnonCreds.IssuerCreateCredentialAsync(agentContext.Wallet, credential.OfferJson, credential.RequestJson, credential.ValuesJson, revocationRegistryId, tailsReader); if (definitionRecord.SupportsRevocation) { await LedgerService.SendRevocationRegistryEntryAsync(agentContext.Wallet, agentContext.Pool, issuerDid, revocationRegistryId, "CL_ACCUM", issuedCredential.RevocRegDeltaJson); credential.CredentialRevocationId = issuedCredential.RevocId; } var msg = new CredentialMessage { CredentialJson = issuedCredential.CredentialJson, RevocationRegistryId = revocationRegistryId }; await credential.TriggerAsync(CredentialTrigger.Issue); await RecordService.UpdateAsync(agentContext.Wallet, credential); try { await MessageService.SendAsync(agentContext.Wallet, msg, connection); } catch (Exception e) { await RecordService.UpdateAsync(agentContext.Wallet, credentialCopy); throw new AgentFrameworkException(ErrorCode.A2AMessageTransmissionError, "Failed to send credential request message", e); } }
public void TestFixtureSetup() { client = new TransparentRedirectClient(CredentialUtils.GetTestCredentials(), true); }
public static string getLoginPostData(string userName, string password) { return string.Format("os_username={0}&os_password={1}&os_cookie=true", HttpUtility.UrlEncode(CredentialUtils.getUserNameWithoutDomain(userName)), HttpUtility.UrlEncode(password)); }
/// <inheritdoc /> public virtual async Task <(CredentialOfferMessage, string)> CreateOfferAsync(IAgentContext agentContext, OfferConfiguration config, string connectionId = null) { Logger.LogInformation(LoggingEvents.CreateCredentialOffer, "DefinitionId {0}, ConnectionId {1}, IssuerDid {2}", config.CredentialDefinitionId, config.IssuerDid); if (!config.MultiPartyOffer && !string.IsNullOrEmpty(connectionId)) { var connection = await ConnectionService.GetAsync(agentContext, connectionId); if (connection.State != ConnectionState.Connected) { throw new AgentFrameworkException(ErrorCode.RecordInInvalidState, $"Connection state was invalid. Expected '{ConnectionState.Connected}', found '{connection.State}'"); } } var offerJson = await AnonCreds.IssuerCreateCredentialOfferAsync(agentContext.Wallet, config.CredentialDefinitionId); var nonce = JObject.Parse(offerJson)["nonce"].ToObject <string>(); // Write offer record to local wallet var credentialRecord = new CredentialRecord { Id = Guid.NewGuid().ToString(), CredentialDefinitionId = config.CredentialDefinitionId, OfferJson = offerJson, MultiPartyOffer = config.MultiPartyOffer, ValuesJson = CredentialUtils.FormatCredentialValues(config.CredentialAttributeValues), State = CredentialState.Offered, }; if (!config.MultiPartyOffer) { credentialRecord.ConnectionId = connectionId; } credentialRecord.SetTag(TagConstants.Nonce, nonce); credentialRecord.SetTag(TagConstants.Role, TagConstants.Issuer); if (!string.IsNullOrEmpty(config.IssuerDid)) { credentialRecord.Tags.Add(TagConstants.IssuerDid, config.IssuerDid); } if (config.Tags != null) { foreach (var tag in config.Tags) { if (!credentialRecord.Tags.Keys.Contains(tag.Key)) { credentialRecord.Tags.Add(tag.Key, tag.Value); } } } await RecordService.AddAsync(agentContext.Wallet, credentialRecord); return(new CredentialOfferMessage { OfferJson = offerJson }, credentialRecord.Id); }
/// <inheritdoc /> public virtual async Task <(CredentialMessage, CredentialRecord)> CreateCredentialAsync(IAgentContext agentContext, string issuerDid, string credentialId, IEnumerable <CredentialPreviewAttribute> values) { var credential = await GetAsync(agentContext, credentialId); if (credential.State != CredentialState.Requested) { throw new AgentFrameworkException(ErrorCode.RecordInInvalidState, $"Credential state was invalid. Expected '{CredentialState.Requested}', found '{credential.State}'"); } if (values != null && values.Any()) { credential.CredentialAttributesValues = values; } var definitionRecord = await SchemaService.GetCredentialDefinitionAsync(agentContext.Wallet, credential.CredentialDefinitionId); var connection = await ConnectionService.GetAsync(agentContext, credential.ConnectionId); if (connection.State != ConnectionState.Connected) { throw new AgentFrameworkException(ErrorCode.RecordInInvalidState, $"Connection state was invalid. Expected '{ConnectionState.Connected}', found '{connection.State}'"); } string revocationRegistryId = null; BlobStorageReader tailsReader = null; if (definitionRecord.SupportsRevocation) { var revocationRecordSearch = await RecordService.SearchAsync <RevocationRegistryRecord>( agentContext.Wallet, SearchQuery.Equal(nameof(RevocationRegistryRecord.CredentialDefinitionId), definitionRecord.Id), null, 5); var revocationRecord = revocationRecordSearch.Single(); // TODO: Credential definition can have multiple revocation registries revocationRegistryId = revocationRecord.Id; tailsReader = await TailsService.OpenTailsAsync(revocationRecord.TailsFile); } var issuedCredential = await AnonCreds.IssuerCreateCredentialAsync(agentContext.Wallet, credential.OfferJson, credential.RequestJson, CredentialUtils.FormatCredentialValues(credential.CredentialAttributesValues), revocationRegistryId, tailsReader); if (definitionRecord.SupportsRevocation) { await LedgerService.SendRevocationRegistryEntryAsync(agentContext.Wallet, await agentContext.Pool, issuerDid, revocationRegistryId, "CL_ACCUM", issuedCredential.RevocRegDeltaJson); credential.CredentialRevocationId = issuedCredential.RevocId; } await credential.TriggerAsync(CredentialTrigger.Issue); await RecordService.UpdateAsync(agentContext.Wallet, credential); var threadId = credential.GetTag(TagConstants.LastThreadId); var credentialMsg = new CredentialMessage { CredentialJson = issuedCredential.CredentialJson, RevocationRegistryId = revocationRegistryId }; credentialMsg.ThreadFrom(threadId); return(credentialMsg, credential); }
public void TestGetVcapCredentialsAsMapNoMatchingName() { var tempVcapCredential = new Dictionary <string, List <VcapCredential> >(); //create credential entries for first service entry var vcapCredential = new VcapCredential() { Credentials = new Credential() { ApiKey = "assistantV1apikey" } }; vcapCredential.Name = "assistantV1"; var vcapCredential2 = new VcapCredential() { Credentials = new Credential() { ApiKey = "assistantV1apikeyCopy" } }; vcapCredential2.Name = "assistantV1Copy"; //map to creds to first service tempVcapCredential.Add("no_matching_name", new List <VcapCredential>() { vcapCredential, vcapCredential2 }); //create credential entries for second service entry var vcapCredential3 = new VcapCredential() { Credentials = new Credential() { ApiKey = "assistantV2apikey" } }; vcapCredential3.Name = "assistantV2"; var vcapCredential4 = new VcapCredential() { Credentials = new Credential() { ApiKey = "assistantV2apikeyCopy" } }; vcapCredential4.Name = "assistantV2Copy"; //map to second service tempVcapCredential.Add("assistant", new List <VcapCredential>() { vcapCredential3, vcapCredential4 }); var vcapString = JsonConvert.SerializeObject(tempVcapCredential); Environment.SetEnvironmentVariable("VCAP_SERVICES", vcapString); Assert.IsNotNull(Environment.GetEnvironmentVariable("VCAP_SERVICES")); var vcapCredentaialsAsMap = CredentialUtils.GetVcapCredentialsAsMap("no_matching_name"); Assert.IsNotNull(vcapCredentaialsAsMap); vcapCredentaialsAsMap.TryGetValue( Authenticator.PropNameApikey, out string extractedKey); Assert.IsTrue(extractedKey == "assistantV1apikey"); }
private void storeLoginSessionCookies(HttpWebRequest request) { lock (sessionMap) { sessionMap[CredentialUtils.getSessionOrTokenKey(server)] = request.CookieContainer; } }
public string login(string userName, string password) { try { service.Credentials = new NetworkCredential(CredentialUtils.getUserNameWithoutDomain(userName), password, CredentialUtils.getUserDomain(userName)); Token = service.login(CredentialUtils.getUserNameWithoutDomain(userName), password); return(Token); } catch (Exception e) { throw new LoginException(e); } }
public void TestFixtureSetup() { client = new ResponsiveSharedClient(CredentialUtils.GetTestCredentials(), true); }
private async Task <(IssuerCreateCredentialResult, RevocationRegistryRecord)> IssueCredentialSafeAsync( IAgentContext agentContext, DefinitionRecord definitionRecord, CredentialRecord credentialRecord) { BlobStorageReader tailsReader = null; RevocationRegistryRecord revocationRecord = null; if (definitionRecord.SupportsRevocation) { revocationRecord = await RecordService.GetAsync <RevocationRegistryRecord>(agentContext.Wallet, definitionRecord.CurrentRevocationRegistryId); tailsReader = await TailsService.OpenTailsAsync(revocationRecord.TailsFile); } try { return(await AnonCreds.IssuerCreateCredentialAsync( agentContext.Wallet, credentialRecord.OfferJson, credentialRecord.RequestJson, CredentialUtils.FormatCredentialValues(credentialRecord.CredentialAttributesValues), definitionRecord.CurrentRevocationRegistryId, tailsReader), revocationRecord); } catch (RevocationRegistryFullException) { if (!definitionRecord.RevocationAutoScale) { throw; } } var registryIndex = definitionRecord.CurrentRevocationRegistryId.Split(':').LastOrDefault()?.Split('-') .FirstOrDefault(); string registryTag; if (int.TryParse(registryIndex, out var currentIndex)) { registryTag = $"{currentIndex + 1}-{definitionRecord.MaxCredentialCount}"; } else { registryTag = $"1-{definitionRecord.MaxCredentialCount}"; } var(_, nextRevocationRecord) = await SchemaService.CreateRevocationRegistryAsync(agentContext, registryTag, definitionRecord); definitionRecord.CurrentRevocationRegistryId = nextRevocationRecord.Id; await RecordService.UpdateAsync(agentContext.Wallet, definitionRecord); tailsReader = await TailsService.OpenTailsAsync(nextRevocationRecord.TailsFile); return(await AnonCreds.IssuerCreateCredentialAsync( agentContext.Wallet, credentialRecord.OfferJson, credentialRecord.RequestJson, CredentialUtils.FormatCredentialValues(credentialRecord.CredentialAttributesValues), nextRevocationRecord.Id, tailsReader), nextRevocationRecord); }
private void runActivateIssueActionsWorker(Action onFinish) { JiraServer server = JiraServerModel.Instance.getServer(new Guid(CurrentActiveIssue.ServerGuid)); if (server != null) { try { int mods = 0; JiraIssue issue = SmartJiraServerFacade.Instance.getIssue(server, CurrentActiveIssue.Key); if (issue != null) { string me = CredentialUtils.getUserNameWithoutDomain(server.UserName); if (issue.Assignee == null || issue.Assignee.Equals("Unknown") || !issue.Assignee.Equals(me)) { jiraStatus.setInfo("Assigning issue to me..."); JiraField assignee = new JiraField("assignee", null) { Values = new List <string> { me }, SettablePropertyName = "name" }; var rawIssueObject = SmartJiraServerFacade.Instance.getRawIssueObject(issue); assignee.setRawIssueObject(rawIssueObject); SmartJiraServerFacade.Instance.updateIssue(issue, new List <JiraField> { assignee }); ++mods; } List <JiraNamedEntity> actions = SmartJiraServerFacade.Instance.getActionsForIssue(issue); JiraNamedEntity action = actions.Find(a => a.Id.Equals(START_PROGRESS_ACTION_ID)); if (action == null) { container.safeInvoke(new MethodInvoker(delegate { ActionSelector sel = new ActionSelector(actions); if (sel.ShowDialog() == DialogResult.OK) { action = sel.SelectedAction; } })); } // foreach (JiraNamedEntity action in actions.Where(action => action.Id.Equals(START_PROGRESS_ACTION_ID))) { if (action != null) { jiraStatus.setInfo("Setting issue in progress..."); SmartJiraServerFacade.Instance.runIssueActionWithoutParams(issue, action); ++mods; } if (mods > 0) { issue = SmartJiraServerFacade.Instance.getIssue(server, CurrentActiveIssue.Key); } } jiraStatus.setInfo("Work on issue " + CurrentActiveIssue.Key + " started"); container.safeInvoke(new MethodInvoker(() => { JiraIssueListModelImpl.Instance.updateIssue(issue); onFinish(); })); } catch (Exception e) { CurrentActiveIssue = null; jiraStatus.setError(FAILED_TO_START_WORK, e); container.safeInvoke(new MethodInvoker(() => PlvsUtils.showError(FAILED_TO_START_WORK, e))); } } else { container.safeInvoke(new MethodInvoker( () => PlvsUtils.showError(FAILED_TO_START_WORK, new Exception("Unknown JIRA server")))); } }