fix lib
This commit is contained in:
parent
49a14d7e6c
commit
38bf638352
@ -1,4 +1,4 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>net6.0</TargetFramework>
|
<TargetFramework>net6.0</TargetFramework>
|
||||||
@ -7,8 +7,7 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Mono.Security" Version="5.4.0.201" />
|
<PackageReference Include="Novell.Directory.Ldap.NETStandard" Version="3.6.0" />
|
||||||
<PackageReference Include="Novell.Directory.LDAP" Version="2.3.8.1" />
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
@ -20,11 +20,8 @@ using System.Text.RegularExpressions;
|
|||||||
|
|
||||||
using ASC.ActiveDirectory.Base.Data;
|
using ASC.ActiveDirectory.Base.Data;
|
||||||
using ASC.Common.Logging;
|
using ASC.Common.Logging;
|
||||||
using ASC.Core;
|
|
||||||
using ASC.Core.Users;
|
using ASC.Core.Users;
|
||||||
|
|
||||||
using Monocert = Mono.Security.X509;
|
|
||||||
using Syscert = System.Security.Cryptography.X509Certificates;
|
|
||||||
|
|
||||||
namespace ASC.ActiveDirectory
|
namespace ASC.ActiveDirectory
|
||||||
{
|
{
|
||||||
@ -133,52 +130,6 @@ namespace ASC.ActiveDirectory
|
|||||||
return Guid.NewGuid().ToString();
|
return Guid.NewGuid().ToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool IsCertInstalled(Syscert.X509Certificate certificate, ILog log = null)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
var monoX509 = new Monocert.X509Certificate(certificate.GetRawCertData());
|
|
||||||
|
|
||||||
var store = WorkContext.IsMono
|
|
||||||
? Monocert.X509StoreManager.CurrentUser.TrustedRoot
|
|
||||||
: Monocert.X509StoreManager.LocalMachine.TrustedRoot;
|
|
||||||
|
|
||||||
return store.Certificates.Contains(monoX509);
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
if (log != null)
|
|
||||||
log.ErrorFormat("IsCertInstalled() failed. Error: {0}", ex);
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static bool TryInstallCert(Syscert.X509Certificate certificate, ILog log = null)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
var monoX509 = new Monocert.X509Certificate(certificate.GetRawCertData());
|
|
||||||
|
|
||||||
var store = WorkContext.IsMono
|
|
||||||
? Monocert.X509StoreManager.CurrentUser.TrustedRoot
|
|
||||||
: Monocert.X509StoreManager.LocalMachine.TrustedRoot;
|
|
||||||
|
|
||||||
// Add the certificate to the store.
|
|
||||||
store.Import(monoX509);
|
|
||||||
store.Certificates.Add(monoX509);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
if (log != null)
|
|
||||||
log.ErrorFormat("TryInstallCert() failed. Error: {0}", ex);
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void SkipErrors(Action method, ILog log = null)
|
public static void SkipErrors(Action method, ILog log = null)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
@ -40,7 +40,7 @@ namespace ASC.ActiveDirectory.Novell.Extensions
|
|||||||
}
|
}
|
||||||
public object GetAttributeValue(LdapEntry ldapEntry, string attributeName, bool getBytes = false)
|
public object GetAttributeValue(LdapEntry ldapEntry, string attributeName, bool getBytes = false)
|
||||||
{
|
{
|
||||||
var attribute = ldapEntry.getAttribute(attributeName);
|
var attribute = ldapEntry.GetAttribute(attributeName);
|
||||||
|
|
||||||
if (attribute == null)
|
if (attribute == null)
|
||||||
return null;
|
return null;
|
||||||
@ -68,7 +68,7 @@ namespace ASC.ActiveDirectory.Novell.Extensions
|
|||||||
|
|
||||||
public string[] GetAttributeArrayValue(LdapEntry ldapEntry, string attributeName)
|
public string[] GetAttributeArrayValue(LdapEntry ldapEntry, string attributeName)
|
||||||
{
|
{
|
||||||
var attribute = ldapEntry.getAttribute(attributeName);
|
var attribute = ldapEntry.GetAttribute(attributeName);
|
||||||
return attribute == null ? null : attribute.StringValueArray;
|
return attribute == null ? null : attribute.StringValueArray;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -182,22 +182,10 @@ namespace ASC.ActiveDirectory.Novell
|
|||||||
{
|
{
|
||||||
var certHash = certificate.GetCertHashString();
|
var certHash = certificate.GetCertHashString();
|
||||||
|
|
||||||
if (LdapUtils.IsCertInstalled(certificate, _log))
|
|
||||||
{
|
|
||||||
AcceptCertificate = true;
|
|
||||||
AcceptCertificateHash = certHash;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (AcceptCertificate)
|
if (AcceptCertificate)
|
||||||
{
|
{
|
||||||
if (AcceptCertificateHash == null || AcceptCertificateHash.Equals(certHash))
|
if (AcceptCertificateHash == null || AcceptCertificateHash.Equals(certHash))
|
||||||
{
|
{
|
||||||
if (LdapUtils.TryInstallCert(certificate, _log))
|
|
||||||
{
|
|
||||||
AcceptCertificateHash = certHash;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -215,9 +203,9 @@ namespace ASC.ActiveDirectory.Novell
|
|||||||
|
|
||||||
public enum LdapScope
|
public enum LdapScope
|
||||||
{
|
{
|
||||||
Base = LdapConnection.SCOPE_BASE,
|
Base = LdapConnection.ScopeBase,
|
||||||
One = LdapConnection.SCOPE_ONE,
|
One = LdapConnection.ScopeOne,
|
||||||
Sub = LdapConnection.SCOPE_SUB
|
Sub = LdapConnection.ScopeSub
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<LdapObject> Search(LdapScope scope, string searchFilter,
|
public List<LdapObject> Search(LdapScope scope, string searchFilter,
|
||||||
@ -282,12 +270,12 @@ namespace ASC.ActiveDirectory.Novell
|
|||||||
var queue = _ldapConnection.Search(searchBase,
|
var queue = _ldapConnection.Search(searchBase,
|
||||||
(int)scope, searchFilter, attributes, false, ldapSearchConstraints);
|
(int)scope, searchFilter, attributes, false, ldapSearchConstraints);
|
||||||
|
|
||||||
while (queue.hasMore())
|
while (queue.HasMore())
|
||||||
{
|
{
|
||||||
LdapEntry nextEntry;
|
LdapEntry nextEntry;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
nextEntry = queue.next();
|
nextEntry = queue.Next();
|
||||||
|
|
||||||
if (nextEntry == null)
|
if (nextEntry == null)
|
||||||
continue;
|
continue;
|
||||||
@ -406,25 +394,25 @@ namespace ASC.ActiveDirectory.Novell
|
|||||||
|
|
||||||
// initially, cookie must be set to an empty string
|
// initially, cookie must be set to an empty string
|
||||||
var pageSize = 2;
|
var pageSize = 2;
|
||||||
sbyte[] cookie = Array.ConvertAll(Encoding.ASCII.GetBytes(""), b => unchecked((sbyte)b));
|
byte[] cookie = Array.ConvertAll(Encoding.ASCII.GetBytes(""), b => unchecked(b));
|
||||||
var i = 0;
|
var i = 0;
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
var requestControls = new LdapControl[1];
|
var requestControls = new LdapControl[1];
|
||||||
requestControls[0] = new LdapPagedResultsControl(pageSize, cookie);
|
requestControls[0] = new SimplePagedResultsControl(pageSize, cookie);
|
||||||
ldapSearchConstraints.setControls(requestControls);
|
ldapSearchConstraints.SetControls(requestControls);
|
||||||
_ldapConnection.Constraints = ldapSearchConstraints;
|
_ldapConnection.Constraints = ldapSearchConstraints;
|
||||||
|
|
||||||
var res = _ldapConnection.Search(searchBase,
|
var res = _ldapConnection.Search(searchBase,
|
||||||
(int)scope, searchFilter, attributes, false, (LdapSearchConstraints)null);
|
(int)scope, searchFilter, attributes, false, (LdapSearchConstraints)null);
|
||||||
|
|
||||||
while (res.hasMore())
|
while (res.HasMore())
|
||||||
{
|
{
|
||||||
LdapEntry nextEntry;
|
LdapEntry nextEntry;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
nextEntry = res.next();
|
nextEntry = res.Next();
|
||||||
|
|
||||||
if (nextEntry == null)
|
if (nextEntry == null)
|
||||||
continue;
|
continue;
|
||||||
@ -441,7 +429,7 @@ namespace ASC.ActiveDirectory.Novell
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
_log.DebugFormat("{0}. DN: {1}", ++i, nextEntry.DN);
|
_log.DebugFormat("{0}. DN: {1}", ++i, nextEntry.Dn);
|
||||||
|
|
||||||
entries.Add(nextEntry);
|
entries.Add(nextEntry);
|
||||||
|
|
||||||
@ -465,11 +453,11 @@ namespace ASC.ActiveDirectory.Novell
|
|||||||
foreach (LdapControl control in controls)
|
foreach (LdapControl control in controls)
|
||||||
{
|
{
|
||||||
/* Is this the LdapPagedResultsResponse control? */
|
/* Is this the LdapPagedResultsResponse control? */
|
||||||
if (!(control is LdapPagedResultsResponse))
|
if (!(control is SimplePagedResultsControl))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
var response = new LdapPagedResultsResponse(control.ID,
|
var response = new SimplePagedResultsControl(control.Id,
|
||||||
control.Critical, control.getValue());
|
control.Critical, control.GetValue());
|
||||||
|
|
||||||
cookie = response.Cookie;
|
cookie = response.Cookie;
|
||||||
}
|
}
|
||||||
@ -498,15 +486,15 @@ namespace ASC.ActiveDirectory.Novell
|
|||||||
ReferralFollowing = true
|
ReferralFollowing = true
|
||||||
};
|
};
|
||||||
|
|
||||||
var ldapSearchResults = _ldapConnection.Search("", LdapConnection.SCOPE_BASE, LdapConstants.OBJECT_FILTER,
|
var ldapSearchResults = _ldapConnection.Search("", LdapConnection.ScopeBase, LdapConstants.OBJECT_FILTER,
|
||||||
new[] { "*", "supportedControls", "supportedCapabilities" }, false, ldapSearchConstraints);
|
new[] { "*", "supportedControls", "supportedCapabilities" }, false, ldapSearchConstraints);
|
||||||
|
|
||||||
while (ldapSearchResults.hasMore())
|
while (ldapSearchResults.HasMore())
|
||||||
{
|
{
|
||||||
LdapEntry nextEntry;
|
LdapEntry nextEntry;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
nextEntry = ldapSearchResults.next();
|
nextEntry = ldapSearchResults.Next();
|
||||||
|
|
||||||
if (nextEntry == null)
|
if (nextEntry == null)
|
||||||
continue;
|
continue;
|
||||||
@ -517,7 +505,7 @@ namespace ASC.ActiveDirectory.Novell
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
var attributeSet = nextEntry.getAttributeSet();
|
var attributeSet = nextEntry.GetAttributeSet();
|
||||||
|
|
||||||
var ienum = attributeSet.GetEnumerator();
|
var ienum = attributeSet.GetEnumerator();
|
||||||
|
|
||||||
@ -532,10 +520,8 @@ namespace ASC.ActiveDirectory.Novell
|
|||||||
.ToList()
|
.ToList()
|
||||||
.Select(s =>
|
.Select(s =>
|
||||||
{
|
{
|
||||||
if (Base64.isLDIFSafe(s)) return s;
|
if (Base64.IsLdifSafe(s)) return s;
|
||||||
var tbyte = SupportClass.ToByteArray(s);
|
s = Base64.Encode(s);
|
||||||
s = Base64.encode(SupportClass.ToSByteArray(tbyte));
|
|
||||||
|
|
||||||
return s;
|
return s;
|
||||||
}).ToArray();
|
}).ToArray();
|
||||||
|
|
||||||
@ -603,7 +589,7 @@ namespace ASC.ActiveDirectory.Novell
|
|||||||
_ldapConnection.SearchConstraints.TimeLimit = 10000;
|
_ldapConnection.SearchConstraints.TimeLimit = 10000;
|
||||||
_ldapConnection.ConnectionTimeout = 10000;
|
_ldapConnection.ConnectionTimeout = 10000;
|
||||||
|
|
||||||
if (_ldapConnection.TLS)
|
if (_ldapConnection.Tls)
|
||||||
{
|
{
|
||||||
_log.Debug("ldapConnection.StopTls();");
|
_log.Debug("ldapConnection.StopTls();");
|
||||||
_ldapConnection.StopTls();
|
_ldapConnection.StopTls();
|
||||||
|
Loading…
Reference in New Issue
Block a user