[英]How to make secure ldap connection with encrypted key?
我正在编写 ldap 客户端代码以连接到安全的 ldap 服务器。
import ldap
ldap.set_option(ldap.OPT_X_TLS_KEYFILE, 'a/b/key.txt')
但是我的 key.txt 包含一个需要密码的加密密钥。
您能否让我知道如何为上述功能传递密码。
我正在使用 python-ldap 模块。
我还尝试通过将解密密钥保存在 StringIO 对象中来使用 StringIO 对象,但是 set_option 方法需要字符串值而不是 StringIO 对象。
python-ldap 模块是 OpenLDAP 包的包装器。 不幸的是,OpenLDAP 无法使用受密码保护的私钥进行操作。 并且您不能为键提供文件描述符,您应该提供一个路径或类似路径的对象以供 c 语言 open() 函数使用。 你有几种方法:
OpenLDAP 源的一部分,其中OPT_X_TLS_KEYFILE
值用作path
参数:
static int
tlsg_getfile( const char *path, gnutls_datum_t *buf )
{
int rc = -1, fd;
struct stat st;
fd = open( path, O_RDONLY );
if ( fd >= 0 && fstat( fd, &st ) == 0 ) {
buf->size = st.st_size;
buf->data = LDAP_MALLOC( st.st_size + 1 );
if ( buf->data ) {
rc = read( fd, buf->data, st.st_size );
close( fd );
if ( rc < st.st_size )
rc = -1;
else
rc = 0;
}
}
return rc;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.