private bool TryCreatePL(out XmlNode[] plXml) { plXml = null; bool flag; try { this.result.SetTask(Strings.InfoCreatePL); string text; string text2; string text3; string certChain = RmsTemplate.DoNotForward.CreatePublishLicense(this.senderAddress, null, this.recipientsAddress, null, this.tenantLicenses, RmsClientManager.EnvironmentHandle, out text, out text2, out text3); if (!RMUtil.TryConvertCertChainToXmlNodeArray(certChain, out plXml)) { this.result.SetFailureResult(Strings.ErrorFailedToCreatePL, null, this.encryptionEnabled); flag = false; } else { this.result.SetSuccessResult(Strings.InfoPLCreated); flag = true; } } catch (RightsManagementException ex) { this.result.SetFailureResult(Strings.ErrorFailedToCreatePL, ex, this.encryptionEnabled); flag = false; } return(flag); }
private void ValidateForEnterprise(IRMConfiguration config) { if (config.ExternalLicensingEnabled && !ExternalAuthentication.GetCurrent().Enabled) { base.WriteError(new OrganizationNotFederatedException(), ErrorCategory.InvalidOperation, base.Identity); } if (config.InternalLicensingEnabled) { Uri rmsserviceLocation = RmsClientManager.GetRMSServiceLocation(OrganizationId.ForestWideOrgId, ServiceType.Certification); if (rmsserviceLocation == null) { base.WriteError(new NoRMSServersFoundException(), ErrorCategory.InvalidOperation, base.Identity); } this.ValidateRmsVersion(rmsserviceLocation, ServiceType.CertificationService); this.ValidateRmsVersion(rmsserviceLocation, ServiceType.LicensingService); } if (!MultiValuedPropertyBase.IsNullOrEmpty(config.LicensingLocation)) { foreach (Uri uri in config.LicensingLocation) { if (string.IsNullOrEmpty(RMUtil.ConvertUriToLicenseUrl(uri))) { base.WriteError(new RmsUrlIsInvalidException(uri), ErrorCategory.InvalidOperation, base.Identity); } this.ValidateRmsVersion(uri, ServiceType.LicensingService); } } }
protected override void InternalValidate() { TaskLogger.LogEnter(); base.InternalValidate(); if (base.HasErrors) { TaskLogger.LogExit(); return; } bool flag = false; if (base.Fields.IsModified("IntranetCertificationUrl") && !RMUtil.IsWellFormedRmServiceUrl(this.IntranetCertificationUrl)) { base.WriteError(new RmsUrlIsInvalidException(this.IntranetCertificationUrl), (ErrorCategory)1000, this.IntranetCertificationUrl); } if (base.Fields.IsModified("ExtranetCertificationUrl") && !RMUtil.IsWellFormedRmServiceUrl(this.ExtranetCertificationUrl)) { base.WriteError(new RmsUrlIsInvalidException(this.ExtranetCertificationUrl), (ErrorCategory)1000, this.ExtranetCertificationUrl); } Uri intranetLicensingUrl; if (base.Fields.IsModified("IntranetLicensingUrl")) { if (!RMUtil.IsWellFormedRmServiceUrl(this.IntranetLicensingUrl)) { base.WriteError(new RmsUrlIsInvalidException(this.IntranetLicensingUrl), (ErrorCategory)1000, this.IntranetLicensingUrl); } intranetLicensingUrl = this.IntranetLicensingUrl; flag = true; } else { intranetLicensingUrl = this.DataObject.IntranetLicensingUrl; } Uri extranetLicensingUrl; if (base.Fields.IsModified("ExtranetLicensingUrl")) { if (!RMUtil.IsWellFormedRmServiceUrl(this.ExtranetLicensingUrl)) { base.WriteError(new RmsUrlIsInvalidException(this.ExtranetLicensingUrl), (ErrorCategory)1000, this.ExtranetLicensingUrl); } extranetLicensingUrl = this.ExtranetLicensingUrl; flag = true; } else { extranetLicensingUrl = this.DataObject.ExtranetLicensingUrl; } if (flag) { foreach (string encodedTemplate in this.DataObject.RMSTemplates) { RmsTemplateType rmsTemplateType; string templateXrml = RMUtil.DecompressTemplate(encodedTemplate, out rmsTemplateType); this.ValidateTemplate(templateXrml, intranetLicensingUrl, extranetLicensingUrl); } } TaskLogger.LogExit(); }
private bool HasCryptoModeChanged(RMSTrustedPublishingDomain oldDefaultTPD, string newSlcCertChainCompressed) { XrmlCertificateChain xrmlCertificateChain = RMUtil.DecompressSLCCertificate(oldDefaultTPD.SLCCertChain); XrmlCertificateChain xrmlCertificateChain2 = RMUtil.DecompressSLCCertificate(newSlcCertChainCompressed); return(xrmlCertificateChain.GetCryptoMode() != xrmlCertificateChain2.GetCryptoMode()); }
private static int CryptoModeFromTpd(TrustedDocDomain tpd) { string compressedCerts = RMUtil.CompressSLCCertificateChain(tpd.m_strLicensorCertChain); XrmlCertificateChain xrmlCertificateChain = RMUtil.DecompressSLCCertificate(compressedCerts); return(xrmlCertificateChain.GetCryptoMode()); }
public static void ThrowIfIsNotWellFormedRmServiceUrl(Uri url, out object failureTarget) { failureTarget = null; if (null != url && !RMUtil.IsWellFormedRmServiceUrl(url)) { failureTarget = url; throw new RmsUrlIsInvalidException(url); } }
private bool WriteToStore(Guid tenantId, Uri url, XmlNode[] rac, XmlNode[] clc, byte version) { bool flag = clc == null; DateTime dateTime = RMUtil.GetRacExpirationTime(rac[0]); DateTime dateTime2 = flag ? DateTime.MaxValue : RMUtil.GetClcExpirationTime(clc[0]); if (RmsClientManager.AppSettings.RacClcStoreExpirationInterval.TotalMinutes != 0.0) { DateTime dateTime3 = DateTime.UtcNow.Add(RmsClientManager.AppSettings.RacClcStoreExpirationInterval); dateTime = ((dateTime3 > dateTime) ? dateTime : dateTime3); dateTime2 = ((dateTime3 > dateTime2) ? dateTime2 : dateTime3); } string text = DrmClientUtils.ConvertXmlNodeArrayToCertificateChain(rac); string text2 = flag ? null : DrmClientUtils.ConvertXmlNodeArrayToCertificateChain(clc); string text3 = null; string text4 = null; try { text3 = DrmClientUtils.AddCertToLicenseStore(text, true); if (flag) { this.perfCounters.FileWrite(1); } else { text4 = DrmClientUtils.AddCertToLicenseStore(text2, false); this.perfCounters.FileWrite(2); } } catch (IOException arg) { RmsLicenseStoreManager.Tracer.TraceError <Guid, Uri, IOException>(0L, "License Store Manager failed to write RAC-CLC to store for tenant ({0}) and URL ({1}). IOException - {2}.", tenantId, url, arg); return(false); } catch (UnauthorizedAccessException arg2) { RmsLicenseStoreManager.Tracer.TraceError <Guid, Uri, UnauthorizedAccessException>(0L, "License Store Manager failed to write RAC-CLC to store for tenant ({0}) and URL ({1}). UnauthorizedAccessException - {2}.", tenantId, url, arg2); return(false); } if (string.IsNullOrEmpty(text3) || (!flag && string.IsNullOrEmpty(text4))) { RmsLicenseStoreManager.Tracer.TraceError <Guid, Uri>(0L, "License Store Manager failed to write RAC-CLC to store for tenant ({0}) and URL ({1}).", tenantId, url); return(false); } RmsLicenseStoreInfo rmsLicenseStoreInfo = new RmsLicenseStoreInfo(tenantId, url, text3, text4, dateTime, dateTime2, version); this.licenseMap.Add(rmsLicenseStoreInfo); this.cache.TryAdd(new MultiValueKey(new object[] { rmsLicenseStoreInfo.TenantId, rmsLicenseStoreInfo.Url }), new TenantLicensePair(rmsLicenseStoreInfo.TenantId, rac, (clc != null) ? clc[0] : null, text, text2, rmsLicenseStoreInfo.RacExpire, rmsLicenseStoreInfo.ClcExpire, version, RmsClientManager.EnvironmentHandle, RmsClientManager.LibraryHandle)); return(true); }
private static object CryptoModeGetter(IPropertyBag propertyBag) { string text = (string)propertyBag[RMSTrustedPublishingDomainSchema.SLCCertChain]; if (!string.IsNullOrEmpty(text)) { XrmlCertificateChain xrmlCertificateChain = RMUtil.DecompressSLCCertificate(text); return(xrmlCertificateChain.GetCryptoMode()); } return(RMSTrustedPublishingDomainSchema.CryptoMode.DefaultValue); }
private IEnumerable <RmsTemplate> AcquireRmsTemplates() { if (this.orgId == OrganizationId.ForestWideOrgId) { return(RmsClientManager.AcquireRmsTemplates(this.orgId, true)); } if (this.irmConfiguration == null || (!this.irmConfiguration.InternalLicensingEnabled && !this.displayTemplatesIfInternalLicensingDisabled)) { return(DrmEmailConstants.EmptyTemplateArray); } RMSTrustedPublishingDomain rmstrustedPublishingDomain = this.FindTPD(); if (rmstrustedPublishingDomain == null) { return(DrmEmailConstants.EmptyTemplateArray); } List <RmsTemplate> list = null; if (!MultiValuedPropertyBase.IsNullOrEmpty(rmstrustedPublishingDomain.RMSTemplates)) { list = new List <RmsTemplate>(rmstrustedPublishingDomain.RMSTemplates.Count + 2); using (MultiValuedProperty <string> .Enumerator enumerator = rmstrustedPublishingDomain.RMSTemplates.GetEnumerator()) { while (enumerator.MoveNext()) { string encodedTemplate = enumerator.Current; RmsTemplateType type = RmsTemplateType.Archived; string templateXrml = RMUtil.DecompressTemplate(encodedTemplate, out type); if (this.ShouldFetch(type)) { list.Add(RmsTemplate.CreateServerTemplateFromTemplateDefinition(templateXrml, type)); } } goto IL_CE; } } list = new List <RmsTemplate>(2); IL_CE: if (this.typeToFetch != RmsTemplateType.Archived && rmstrustedPublishingDomain.Default) { list.Add(RmsTemplate.DoNotForward); if (this.irmConfiguration.InternetConfidentialEnabled) { list.Add(RmsTemplate.InternetConfidential); } } return(list); }
private static string[] GetTrustedDomainChainArrayFromCompressedString(string compressedCertChainString) { string[] result; try { XrmlCertificateChain xrmlCertificateChain = RMUtil.DecompressSLCCertificate(compressedCertChainString); result = xrmlCertificateChain.ToStringArray(); } catch (FormatException ex) { throw new ConfigurationProviderException(true, "ConfigurationInformationProvider failed to read TPD from compressed form", ex); } catch (InvalidRpmsgFormatException ex2) { throw new ConfigurationProviderException(true, "ConfigurationInformationProvider failed to read TPD from compressed form", ex2); } return(result); }
public TrustedDocDomain Import(Guid externalDirectoryOrgId) { RmsUtil.ThrowIfGuidEmpty(externalDirectoryOrgId, "externalDirectoryOrgId"); X509Certificate2 authenticationCertificate = this.LoadAuthenticationCertificate(); this.ThrowIfAuthenticationCertificateIsInvalid(authenticationCertificate); ITenantManagementService tenantManagementService = this.CreateRmsOnlineWebServiceProxy(authenticationCertificate); TrustedDocDomain result; try { TenantInfo[] tenantInfo = tenantManagementService.GetTenantInfo(new string[] { externalDirectoryOrgId.ToString() }); RmsUtil.ThrowIfTenantInfoisNull(tenantInfo, externalDirectoryOrgId); RmsUtil.ThrowIfZeroOrMultipleTenantInfoObjectsReturned(tenantInfo, externalDirectoryOrgId); RmsUtil.ThrowIfErrorInfoObjectReturned(tenantInfo[0], externalDirectoryOrgId); RmsUtil.ThrowIfTenantInfoDoesNotIncludeActiveTPD(tenantInfo[0], externalDirectoryOrgId); RmsUtil.ThrowIfTpdDoesNotIncludeKeyInformation(tenantInfo[0].ActivePublishingDomain, externalDirectoryOrgId); RmsUtil.ThrowIfTpdDoesNotIncludeSLC(tenantInfo[0].ActivePublishingDomain, externalDirectoryOrgId); RmsUtil.ThrowIfTpdDoesNotIncludeTemplates(tenantInfo[0].ActivePublishingDomain, externalDirectoryOrgId); RmsUtil.ThrowIfTenantInfoDoesNotIncludeLicensingUrls(tenantInfo[0], externalDirectoryOrgId); RmsUtil.ThrowIfTenantInfoDoesNotIncludeCertificationUrls(tenantInfo[0], externalDirectoryOrgId); this.IntranetLicensingUrl = RMUtil.ConvertUriToLicenseLocationDistributionPoint(tenantInfo[0].LicensingIntranetDistributionPointUrl); this.ExtranetLicensingUrl = RMUtil.ConvertUriToLicenseLocationDistributionPoint(tenantInfo[0].LicensingExtranetDistributionPointUrl); this.IntranetCertificationUrl = RMUtil.ConvertUriToLicenseLocationDistributionPoint(tenantInfo[0].CertificationIntranetDistributionPointUrl); this.ExtranetCertificationUrl = RMUtil.ConvertUriToLicenseLocationDistributionPoint(tenantInfo[0].CertificationExtranetDistributionPointUrl); result = RmsUtil.ConvertFromRmsOnlineTrustedDocDomain(tenantInfo[0].ActivePublishingDomain); } catch (FaultException <ArgumentException> innerException) { throw new ImportTpdException("Caught FaultException<ArgumentException> while obtaining TPD from RMS Online", innerException); } catch (CommunicationException innerException2) { throw new ImportTpdException("Unable to communicate with RMS Online key sharing web service", innerException2); } catch (TimeoutException innerException3) { throw new ImportTpdException("The TPD import request to the RMS Online key sharing web service has timed out", innerException3); } return(result); }
public void Save(IConfigurable instance) { if (this.orgId == OrganizationId.ForestWideOrgId) { throw new NotSupportedException(); } RmsTemplatePresentation rmsTemplatePresentation = instance as RmsTemplatePresentation; if (rmsTemplatePresentation == null) { throw new ArgumentException("passed in instance not of type RmsTemplatePresentation", "instance"); } Guid templateGuid = rmsTemplatePresentation.TemplateGuid; RMSTrustedPublishingDomain rmstrustedPublishingDomain = this.FindDefaultTPD(); if (rmstrustedPublishingDomain == null) { return; } if (!MultiValuedPropertyBase.IsNullOrEmpty(rmstrustedPublishingDomain.RMSTemplates)) { string text = null; string text2 = null; foreach (string text3 in rmstrustedPublishingDomain.RMSTemplates) { RmsTemplateType rmsTemplateType; string text4 = RMUtil.DecompressTemplate(text3, out rmsTemplateType); Guid templateGuidFromLicense = DrmClientUtils.GetTemplateGuidFromLicense(text4); if (templateGuidFromLicense == templateGuid && rmsTemplateType != rmsTemplatePresentation.Type) { text = text3; text2 = RMUtil.CompressTemplate(text4, rmsTemplatePresentation.Type); break; } } if (!string.IsNullOrEmpty(text) && !string.IsNullOrEmpty(text2)) { rmstrustedPublishingDomain.RMSTemplates.Remove(text); rmstrustedPublishingDomain.RMSTemplates.Add(text2); this.adSession.Save(rmstrustedPublishingDomain); } } }
private static string GetTemplateFromCompressedString(string compressedTemplateString) { string result; try { RmsTemplateType rmsTemplateType; result = RMUtil.DecompressTemplate(compressedTemplateString, out rmsTemplateType); } catch (FormatException ex) { throw new ConfigurationProviderException(true, ex); } catch (InvalidRpmsgFormatException ex2) { throw new ConfigurationProviderException(true, ex2); } return(result); }
public override void ReadData(IConfigurationSession session) { RMSTrustedPublishingDomain[] array = session.Find <RMSTrustedPublishingDomain>(null, QueryScope.SubTree, null, null, 0); if (array == null || array.Length == 0) { return; } foreach (RMSTrustedPublishingDomain rmstrustedPublishingDomain in array) { if (rmstrustedPublishingDomain.Default && !MultiValuedPropertyBase.IsNullOrEmpty(rmstrustedPublishingDomain.RMSTemplates)) { foreach (string encodedTemplate in rmstrustedPublishingDomain.RMSTemplates) { string text = null; try { RmsTemplateType rmsTemplateType; text = RMUtil.DecompressTemplate(encodedTemplate, out rmsTemplateType); if (rmsTemplateType == RmsTemplateType.Distributed) { RmsTemplate rmsTemplate = RmsTemplate.CreateServerTemplateFromTemplateDefinition(text, rmsTemplateType); this.templates.Add(rmsTemplate.Id, rmsTemplate); this.estimatedSize += rmsTemplate.ItemSize + 16L; } } catch (FormatException arg) { RmsConfiguration.Tracer.TraceError <string, FormatException>((long)this.GetHashCode(), "Failed to read template {0}. Error {1}", text, arg); } catch (InvalidRpmsgFormatException arg2) { RmsConfiguration.Tracer.TraceError <string, InvalidRpmsgFormatException>((long)this.GetHashCode(), "Failed to read template {0}. Error {1}", text, arg2); } catch (RightsManagementException arg3) { RmsConfiguration.Tracer.TraceError <string, RightsManagementException>((long)this.GetHashCode(), "Failed to read template {0}. Error {1}", text, arg3); } } } } }
private static int CryptoModeFromCompressedSLC(string compressedSLCCertChain) { XrmlCertificateChain xrmlCertificateChain = RMUtil.DecompressSLCCertificate(compressedSLCCertChain); return(xrmlCertificateChain.GetCryptoMode()); }
protected override void InternalProcessRecord() { TaskLogger.LogEnter(); ((IConfigurationSession)base.DataSession).SessionSettings.IsSharedConfigChecked = true; bool flag = false; IRMConfiguration irmconfiguration = IRMConfiguration.Read((IConfigurationSession)base.DataSession, out flag); RMSTrustedPublishingDomain rmstrustedPublishingDomain = null; if (irmconfiguration == null) { base.WriteError(new FailedToAccessIrmConfigurationException(), (ErrorCategory)1002, this.Identity); } if (this.IntranetCertificationUrl != null) { this.DataObject.IntranetCertificationUrl = RMUtil.ConvertUriToCertificateLocationDistributionPoint(this.IntranetCertificationUrl); } if (this.ExtranetCertificationUrl != null) { this.DataObject.ExtranetCertificationUrl = RMUtil.ConvertUriToCertificateLocationDistributionPoint(this.ExtranetCertificationUrl); } if (this.IntranetLicensingUrl != null) { if (irmconfiguration.LicensingLocation.Contains(this.DataObject.IntranetLicensingUrl)) { irmconfiguration.LicensingLocation.Remove(this.DataObject.IntranetLicensingUrl); } Uri uri = RMUtil.ConvertUriToLicenseLocationDistributionPoint(this.IntranetLicensingUrl); if (!irmconfiguration.LicensingLocation.Contains(uri)) { irmconfiguration.LicensingLocation.Add(uri); } this.DataObject.IntranetLicensingUrl = uri; } if (this.ExtranetLicensingUrl != null) { if (irmconfiguration.LicensingLocation.Contains(this.DataObject.ExtranetLicensingUrl)) { irmconfiguration.LicensingLocation.Remove(this.DataObject.ExtranetLicensingUrl); } Uri uri2 = RMUtil.ConvertUriToLicenseLocationDistributionPoint(this.ExtranetLicensingUrl); if (!irmconfiguration.LicensingLocation.Contains(uri2)) { irmconfiguration.LicensingLocation.Add(uri2); } this.DataObject.ExtranetLicensingUrl = uri2; } if (this.Default && !this.DataObject.Default) { this.DataObject.Default = true; try { ImportRmsTrustedPublishingDomain.ChangeDefaultTPDAndUpdateIrmConfigData((IConfigurationSession)base.DataSession, irmconfiguration, this.DataObject, out rmstrustedPublishingDomain); irmconfiguration.ServerCertificatesVersion++; } catch (RightsManagementServerException ex) { base.WriteError(new FailedToGenerateSharedKeyException(ex), (ErrorCategory)1000, this.Identity); } } if (rmstrustedPublishingDomain != null) { this.WriteWarning(Strings.WarningChangeDefaultTPD(rmstrustedPublishingDomain.Name, this.DataObject.Name)); base.DataSession.Save(rmstrustedPublishingDomain); } base.DataSession.Save(irmconfiguration); base.InternalProcessRecord(); TaskLogger.LogExit(); }
private static bool ValidateResponsesAndUpdateServerInfo(AcquireServerInfoAsyncResult result, out LocalizedString errStr) { errStr = LocalizedString.Empty; if (result.ServiceLocationResponses == null) { errStr = ServerStrings.InvalidServiceLocationResponse; RmsServerInfoManager.Tracer.TraceError(0L, "ServiceLocation responses is null"); return(false); } if (result.ServiceLocationResponses.Length != 4) { errStr = ServerStrings.IncorrectEntriesInServiceLocationResponse(result.ServiceLocationResponses.Length, 4); RmsServerInfoManager.Tracer.TraceError <int>(0L, "Number of entries in the response is {0}. Expected 4", result.ServiceLocationResponses.Length); return(false); } ServiceLocationResponse[] serviceLocationResponses = result.ServiceLocationResponses; int i = 0; while (i < serviceLocationResponses.Length) { ServiceLocationResponse serviceLocationResponse = serviceLocationResponses[i]; Uri uri; bool result2; if (!RMUtil.TryCreateUri(serviceLocationResponse.URL, out uri)) { errStr = ServerStrings.InvalidRmsUrl(serviceLocationResponse.Type, serviceLocationResponse.URL); RmsServerInfoManager.Tracer.TraceError <string>(0L, "Invalid response from the service location. {0} is an invalid URI", serviceLocationResponse.URL); result2 = false; } else { if (RMUtil.IsWellFormedRmServiceUrl(uri)) { switch (serviceLocationResponse.Type) { case ServiceType.ServerLicensingWSService: if (uri.Scheme != Uri.UriSchemeHttps) { errStr = ServerStrings.InvalidUrlScheme(serviceLocationResponse.Type, uri); RmsServerInfoManager.Tracer.TraceError <Uri>(0L, "The Uri scheme for the server licensing WS service {0} is not https", uri); return(false); } result.ServerInfo.ServerLicensingWSPipeline = uri; break; case ServiceType.CertificationWSService: if (uri.Scheme != Uri.UriSchemeHttps) { errStr = ServerStrings.InvalidUrlScheme(serviceLocationResponse.Type, uri); RmsServerInfoManager.Tracer.TraceError <Uri>(0L, "The Uri scheme for the certification WS service {0} is not https", uri); return(false); } result.ServerInfo.CertificationWSPipeline = uri; break; case ServiceType.ServerLicensingMexService: result.ServerLicensingMExUri = RmsServerInfoManager.ConvertToWsdlUrl(serviceLocationResponse.URL); break; case ServiceType.CertificationMexService: result.CertificationMExUri = RmsServerInfoManager.ConvertToWsdlUrl(serviceLocationResponse.URL); break; } i++; continue; } errStr = ServerStrings.InvalidRmsUrl(serviceLocationResponse.Type, serviceLocationResponse.URL); RmsServerInfoManager.Tracer.TraceError <string>(0L, "Invalid response from the service location. {0} is an invalid RMS URI", serviceLocationResponse.URL); result2 = false; } return(result2); } if (result.ServerInfo.CertificationWSPipeline == null || result.ServerInfo.ServerLicensingWSPipeline == null || result.CertificationMExUri == null || result.ServerLicensingMExUri == null) { errStr = ServerStrings.InvalidServiceLocationResponse; return(false); } return(true); }
public static void AcquireTenantLicenses(RmsClientManagerContext clientContext, XmlNode[] machineCertificateChain, string identity, out XmlNode[] racXml, out XmlNode[] clcXml) { ArgumentValidator.ThrowIfNull("clientContext", clientContext); ArgumentValidator.ThrowIfNull("machineCertificateChain", machineCertificateChain); ArgumentValidator.ThrowIfNullOrEmpty("identity", identity); racXml = null; clcXml = null; ServerManager.InitializeIfNeeded(); if (ServerManager.instance.isHostingInstance) { PerTenantRMSTrustedPublishingDomainConfiguration tenantTrustedPublishingDomainConfig = ServerManager.instance.GetTenantTrustedPublishingDomainConfig(clientContext); ContextProvider contextProvider = null; try { IRightsAccountCertificateGenerator rightsAccountCertificateGenerator; IClientLicensorCertificateGenerator clientLicensorCertificateGenerator; try { contextProvider = new ContextProvider(clientContext, tenantTrustedPublishingDomainConfig); rightsAccountCertificateGenerator = GeneratorFactory.CreateRightsAccountCertificateGenerator(contextProvider); clientLicensorCertificateGenerator = GeneratorFactory.CreateClientLicensorCertificateGenerator(contextProvider); } catch (ConfigurationProviderException ex) { ServerManagerLog.LogEvent(ServerManagerLog.Subcomponent.AcquireTenantLicenses, ServerManagerLog.EventType.Error, clientContext, string.Format("Failed to create Generator with Exception: {0}", ServerManagerLog.GetExceptionLogString(ex, ServerManagerLog.ExceptionLogOption.IncludeStack | ServerManagerLog.ExceptionLogOption.IncludeInnerException))); throw new RightsManagementServerException(ServerStrings.FailedToCreateLicenseGenerator(clientContext.OrgId.ToString(), "RacClc"), ex); } catch (CertificationException ex2) { ServerManagerLog.LogEvent(ServerManagerLog.Subcomponent.AcquireTenantLicenses, ServerManagerLog.EventType.Error, clientContext, string.Format("Failed to create Generator with WellKnownErrorCode {0}, Exception: {1}", ex2.ErrorCode, ServerManagerLog.GetExceptionLogString(ex2, ServerManagerLog.ExceptionLogOption.IncludeStack | ServerManagerLog.ExceptionLogOption.IncludeInnerException))); throw new RightsManagementServerException(ServerStrings.FailedToCreateLicenseGenerator(clientContext.OrgId.ToString(), "Rac"), ex2); } catch (PublishingException ex3) { ServerManagerLog.LogEvent(ServerManagerLog.Subcomponent.AcquireTenantLicenses, ServerManagerLog.EventType.Error, clientContext, string.Format("Failed to create Generator with WellKnownErrorCode {0}, Exception: {1}", ex3.ErrorCode, ServerManagerLog.GetExceptionLogString(ex3, ServerManagerLog.ExceptionLogOption.IncludeStack | ServerManagerLog.ExceptionLogOption.IncludeInnerException))); throw new RightsManagementServerException(ServerStrings.FailedToCreateLicenseGenerator(clientContext.OrgId.ToString(), "Clc"), ex3); } XrmlCertificateChain xrmlCertificateChain = new XrmlCertificateChain(DrmClientUtils.ConvertXmlNodeArrayToStringArray(machineCertificateChain)); ServerManagerLog.LogEvent(ServerManagerLog.Subcomponent.AcquireTenantLicenses, ServerManagerLog.EventType.Entry, clientContext, string.Format("AcquireTenantLicenses for identity {0}", identity)); XrmlCertificateChain xrmlCertificateChain2; XrmlCertificateChain xrmlCertificateChain3; try { string text = ServerManager.ReadOrganizationRacKeysFromIRMConfig(clientContext.OrgId); xrmlCertificateChain2 = rightsAccountCertificateGenerator.AcquireCertificate(xrmlCertificateChain, identity, text); xrmlCertificateChain3 = clientLicensorCertificateGenerator.AcquireCertificate(xrmlCertificateChain2); } catch (CertificationException ex4) { ServerManagerLog.LogEvent(ServerManagerLog.Subcomponent.AcquireTenantLicenses, ServerManagerLog.EventType.Error, clientContext, string.Format("Failed to AcquireTenantLicenses with WellKnownErrorCode {0}, Exception: {1}", ex4.ErrorCode, ServerManagerLog.GetExceptionLogString(ex4, ServerManagerLog.ExceptionLogOption.IncludeStack | ServerManagerLog.ExceptionLogOption.IncludeInnerException))); throw new RightsManagementServerException(ServerStrings.FailedToAcquireRacAndClc(clientContext.OrgId.ToString(), identity), ex4); } catch (PublishingException ex5) { ServerManagerLog.LogEvent(ServerManagerLog.Subcomponent.AcquireTenantLicenses, ServerManagerLog.EventType.Error, clientContext, string.Format("Failed to AcquireTenantLicenses with WellKnownErrorCode {0}, Exception: {1}", ex5.ErrorCode, ServerManagerLog.GetExceptionLogString(ex5, ServerManagerLog.ExceptionLogOption.IncludeStack | ServerManagerLog.ExceptionLogOption.IncludeInnerException))); throw new RightsManagementServerException(ServerStrings.FailedToAcquireRacAndClc(clientContext.OrgId.ToString(), identity), ex5); } if (!RMUtil.TryConvertCertChainStringArrayToXmlNodeArray(xrmlCertificateChain2.ToStringArray(), out racXml)) { throw new RightsManagementServerException(ServerStrings.FailedToAcquireRacAndClc(clientContext.OrgId.ToString(), identity), true); } if (!RMUtil.TryConvertCertChainStringArrayToXmlNodeArray(xrmlCertificateChain3.ToStringArray(), out clcXml)) { throw new RightsManagementServerException(ServerStrings.FailedToAcquireRacAndClc(clientContext.OrgId.ToString(), identity), true); } return; } finally { if (contextProvider != null) { contextProvider.Dispose(); } } } RpcClientWrapper.AcquireTenantLicenses(clientContext, machineCertificateChain, identity, out racXml, out clcXml); }
public static string ResealRACKey(IPerTenantRMSTrustedPublishingDomainConfiguration config, string originalSharedKey) { ArgumentValidator.ThrowIfNull("config", config); ArgumentValidator.ThrowIfNullOrEmpty("config.CompressedSLCCertChain", config.CompressedSLCCertChain); ArgumentValidator.ThrowIfNullOrEmpty("originalSharedKey", originalSharedKey); ContextProvider contextProvider = null; string result; try { contextProvider = new ContextProvider(config); IRightsAccountCertificateGenerator rightsAccountCertificateGenerator = GeneratorFactory.CreateRightsAccountCertificateGenerator(contextProvider); result = rightsAccountCertificateGenerator.ResealKey(originalSharedKey, RMUtil.DecompressSLCCertificate(config.CompressedSLCCertChain)); } catch (ConfigurationProviderException innerException) { throw new RightsManagementServerException(ServerStrings.FailedToResealKey, innerException); } catch (CertificationException innerException2) { throw new RightsManagementServerException(ServerStrings.FailedToResealKey, innerException2); } catch (RightsManagementException innerException3) { throw new RightsManagementServerException(ServerStrings.FailedToResealKey, innerException3, true); } finally { if (contextProvider != null) { contextProvider.Dispose(); } } return(result); }
public bool ReadFromStore(Guid tenantId, Uri url, byte version, out TenantLicensePair tenantLicenses) { if (null == url) { throw new ArgumentNullException("url"); } MultiValueKey multiValueKey = new MultiValueKey(new object[] { tenantId, url }); RmsLicenseStoreInfo rmsLicenseStoreInfo; if (this.ReadFromCache(multiValueKey, out tenantLicenses)) { this.licenseMap.TryGet(multiValueKey, out rmsLicenseStoreInfo); return(true); } if (!this.licenseMap.TryGet(multiValueKey, out rmsLicenseStoreInfo)) { RmsLicenseStoreManager.Tracer.TraceDebug <MultiValueKey>(0L, "License Store Manager doesn't have entry in map for key ({0}) or certs are expired.", multiValueKey); return(false); } string text = null; string text2 = null; try { text = DrmClientUtils.GetCertFromLicenseStore(rmsLicenseStoreInfo.RacFileName); if (!string.IsNullOrEmpty(rmsLicenseStoreInfo.ClcFileName)) { text2 = DrmClientUtils.GetCertFromLicenseStore(rmsLicenseStoreInfo.ClcFileName); this.perfCounters.FileRead(2); } else { this.perfCounters.FileRead(1); } } catch (IOException arg) { RmsLicenseStoreManager.Tracer.TraceError <MultiValueKey, IOException>(0L, "License Store Manager failed to read certs from store for key ({0}). IOException - {1}.", multiValueKey, arg); return(false); } catch (UnauthorizedAccessException arg2) { RmsLicenseStoreManager.Tracer.TraceError <MultiValueKey, UnauthorizedAccessException>(0L, "License Store Manager failed to read certs from store for key ({0}). UnauthorizedAccessException - {1}.", multiValueKey, arg2); return(false); } catch (SecurityException arg3) { RmsLicenseStoreManager.Tracer.TraceError <MultiValueKey, SecurityException>(0L, "License Store Manager failed to read certs from store for key ({0}). SecurityException - {1}.", multiValueKey, arg3); return(false); } XmlNode[] rac; XmlNode[] array; if (!string.IsNullOrEmpty(text) && !string.IsNullOrEmpty(text2) && RMUtil.TryConvertAppendedCertsToXmlNodeArray(text, out rac) && RMUtil.TryConvertAppendedCertsToXmlNodeArray(text2, out array)) { tenantLicenses = new TenantLicensePair(tenantId, rac, array[0], null, DrmClientUtils.ConvertXmlNodeArrayToCertificateChain(array), rmsLicenseStoreInfo.RacExpire, rmsLicenseStoreInfo.ClcExpire, rmsLicenseStoreInfo.Version, RmsClientManager.EnvironmentHandle, RmsClientManager.LibraryHandle); this.cache.TryAdd(multiValueKey, tenantLicenses); return(true); } if (!string.IsNullOrEmpty(text) && RMUtil.TryConvertAppendedCertsToXmlNodeArray(text, out rac) && version == rmsLicenseStoreInfo.Version) { tenantLicenses = new TenantLicensePair(tenantId, rac, null, null, null, rmsLicenseStoreInfo.RacExpire, rmsLicenseStoreInfo.ClcExpire, rmsLicenseStoreInfo.Version, RmsClientManager.EnvironmentHandle, RmsClientManager.LibraryHandle); this.cache.TryAdd(multiValueKey, tenantLicenses); return(true); } RmsLicenseStoreManager.Tracer.TraceError <MultiValueKey>(0L, "License Store Manager failed to read certs from store for key ({0}) - certs are empty or invalid.", multiValueKey); this.licenseMap.Remove(multiValueKey); return(false); }
public static bool AreRmsOnlinePreRequisitesMet(IRMConfiguration irmConfiguration) { RmsUtil.ThrowIfParameterNull(irmConfiguration, "irmConfiguration"); return(RMUtil.IsWellFormedRmServiceUrl(irmConfiguration.RMSOnlineKeySharingLocation)); }
private static object IsRMSOnlineGetter(IPropertyBag propertyBag) { string text = (string)propertyBag[RMSTrustedPublishingDomainSchema.SLCCertChain]; return(!string.IsNullOrEmpty(text) && RMSUtil.IsRMSOnline(RMUtil.DecompressSLCCertificate(text).ToStringArray())); }