]> granicus.if.org Git - sudo/commitdiff
Add support for base64 secrets in ldap.conf and ldap.secret.
authorTodd C. Miller <Todd.Miller@courtesan.com>
Thu, 10 Jul 2014 21:31:11 +0000 (15:31 -0600)
committerTodd C. Miller <Todd.Miller@courtesan.com>
Thu, 10 Jul 2014 21:31:11 +0000 (15:31 -0600)
Based on an idea from anthony AT rlost DOT com

doc/sudoers.ldap.cat
doc/sudoers.ldap.man.in
doc/sudoers.ldap.mdoc.in
plugins/sudoers/ldap.c

index eb67c83ab1ac5099e4a09e35dca4f4b4ffb28091..d932c7f6b90ccec795a4a7edbb163bb35797d3d2 100644 (file)
@@ -378,7 +378,15 @@ D\bDE\bES\bSC\bCR\bRI\bIP\bPT\bTI\bIO\bON\bN
      B\bBI\bIN\bND\bDP\bPW\bW _\bs_\be_\bc_\br_\be_\bt
            The B\bBI\bIN\bND\bDP\bPW\bW parameter specifies the password to use when performing
            LDAP operations.  This is typically used in conjunction with the
-           B\bBI\bIN\bND\bDD\bDN\bN parameter.
+           B\bBI\bIN\bND\bDD\bDN\bN parameter.  The _\bs_\be_\bc_\br_\be_\bt may be a plain text password or a
+           base64-encoded string with a ``base64:'' prefix.  For example:
+
+               BINDPW base64:dGVzdA==
+
+           If a plain text password is used, it should be a simple string
+           without quotes.  Plain text passwords may not include the comment
+           character (`#') and the escaping of special characters with a
+           backslash (`\') is not supported.
 
      R\bRO\bOO\bOT\bTB\bBI\bIN\bND\bDD\bDN\bN _\bD_\bN
            The R\bRO\bOO\bOT\bTB\bBI\bIN\bND\bDD\bDN\bN parameter specifies the identity, in the form of a
@@ -476,12 +484,18 @@ D\bDE\bES\bSC\bCR\bRI\bIP\bPT\bTI\bIO\bON\bN
      T\bTL\bLS\bS_\b_K\bKE\bEY\bYP\bPW\bW _\bs_\be_\bc_\br_\be_\bt
            The T\bTL\bLS\bS_\b_K\bKE\bEY\bYP\bPW\bW contains the password used to decrypt the key
            database on clients using the Tivoli Directory Server LDAP library.
-           This should be a simple string without quotes.  The password may
-           not include the comment character (`#') and escaping of special
-           characters with a backslash (`\') is not supported.  If this option
-           is used, _\b/_\be_\bt_\bc_\b/_\bl_\bd_\ba_\bp_\b._\bc_\bo_\bn_\bf must not be world-readable to avoid
-           exposing the password.  Alternately, a _\bs_\bt_\ba_\bs_\bh _\bf_\bi_\bl_\be can be used to
-           store the password in encrypted form (see below).
+           The _\bs_\be_\bc_\br_\be_\bt may be a plain text password or a base64-encoded string
+           with a ``base64:'' prefix.  For example:
+
+               TLS_KEYPW base64:dGVzdA==
+
+           If a plain text password is used, it should be a simple string
+           without quotes.  Plain text passwords may not include the comment
+           character (`#') and the escaping of special characters with a
+           backslash (`\') is not supported.  If this option is used,
+           _\b/_\be_\bt_\bc_\b/_\bl_\bd_\ba_\bp_\b._\bc_\bo_\bn_\bf must not be world-readable to avoid exposing the
+           password.  Alternately, a _\bs_\bt_\ba_\bs_\bh _\bf_\bi_\bl_\be can be used to store the
+           password in encrypted form (see below).
 
            If no T\bTL\bLS\bS_\b_K\bKE\bEY\bYP\bPW\bW is specified, a _\bs_\bt_\ba_\bs_\bh _\bf_\bi_\bl_\be will be used if it
            exists.  The _\bs_\bt_\ba_\bs_\bh _\bf_\bi_\bl_\be must have the same path as the file
@@ -812,4 +826,4 @@ D\bDI\bIS\bSC\bCL\bLA\bAI\bIM\bME\bER\bR
      file distributed with s\bsu\bud\bdo\bo or http://www.sudo.ws/sudo/license.html for
      complete details.
 
-Sudo 1.8.10                    February 7, 2014                    Sudo 1.8.10
+Sudo 1.8.11                      July 10, 2014                     Sudo 1.8.11
index 6cbd5939e3874c8b8b41b54c3cfea666a7137a8d..c28ff573021d3d00ca459bb11aef9fd6c077941c 100644 (file)
@@ -16,7 +16,7 @@
 .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 .\" ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 .\"
-.TH "SUDOERS.LDAP" "8" "February 7, 2014" "Sudo @PACKAGE_VERSION@" "OpenBSD System Manager's Manual"
+.TH "SUDOERS.LDAP" "8" "July 10, 2014" "Sudo @PACKAGE_VERSION@" "OpenBSD System Manager's Manual"
 .nh
 .if n .ad l
 .SH "NAME"
@@ -698,6 +698,27 @@ parameter specifies the password to use when performing LDAP operations.
 This is typically used in conjunction with the
 \fBBINDDN\fR
 parameter.
+The
+\fIsecret\fR
+may be a plain text password or a base64-encoded string with a
+\(lqbase64:\(rq
+prefix.
+For example:
+.nf
+.sp
+.RS 10n
+BINDPW base64:dGVzdA==
+.RE
+.fi
+.RS 6n
+.sp
+If a plain text password is used, it should be a simple string without quotes.
+Plain text passwords may not include the comment character
+(\(oq#\(cq)
+and the escaping of special characters with a backslash
+(\(oq\e\(cq)
+is not supported.
+.RE
 .TP 6n
 \fBROOTBINDDN\fR \fIDN\fR
 The
@@ -848,10 +869,24 @@ The
 \fBTLS_KEYPW\fR
 contains the password used to decrypt the key database on clients
 using the Tivoli Directory Server LDAP library.
-This should be a simple string without quotes.
-The password may not include the comment character
+The
+\fIsecret\fR
+may be a plain text password or a base64-encoded string with a
+\(lqbase64:\(rq
+prefix.
+For example:
+.nf
+.sp
+.RS 10n
+TLS_KEYPW base64:dGVzdA==
+.RE
+.fi
+.RS 6n
+.sp
+If a plain text password is used, it should be a simple string without quotes.
+Plain text passwords may not include the comment character
 (\(oq#\(cq)
-and escaping of special characters with a backslash
+and the escaping of special characters with a backslash
 (\(oq\e\(cq)
 is not supported.
 If this option is used,
@@ -885,6 +920,7 @@ The
 utility can be used to manage the key database and create a
 \fIstash file\fR.
 This option is only supported by the Tivoli LDAP libraries.
+.RE
 .TP 6n
 \fBTLS_RANDFILE\fR \fIfile name\fR
 The
index 891e3e1f910d60b006c9eb192e7078163ebf6b72..1cdc965fe7f82365bfbe77cf2efd0f04e8b81f07 100644 (file)
@@ -14,7 +14,7 @@
 .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 .\" ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 .\"
-.Dd February 7, 2014
+.Dd July 10, 2014
 .Dt SUDOERS.LDAP @mansectsu@
 .Os Sudo @PACKAGE_VERSION@
 .Sh NAME
@@ -658,6 +658,22 @@ parameter specifies the password to use when performing LDAP operations.
 This is typically used in conjunction with the
 .Sy BINDDN
 parameter.
+The
+.Ar secret
+may be a plain text password or a base64-encoded string with a
+.Dq base64:
+prefix.
+For example:
+.Bd -literal -offset 4n
+BINDPW base64:dGVzdA==
+.Ed
+.Pp
+If a plain text password is used, it should be a simple string without quotes.
+Plain text passwords may not include the comment character
+.Pq Ql #
+and the escaping of special characters with a backslash
+.Pq Ql \e
+is not supported.
 .It Sy ROOTBINDDN Ar DN
 The
 .Sy ROOTBINDDN
@@ -779,10 +795,20 @@ The
 .Sy TLS_KEYPW
 contains the password used to decrypt the key database on clients
 using the Tivoli Directory Server LDAP library.
-This should be a simple string without quotes.
-The password may not include the comment character
+The
+.Ar secret
+may be a plain text password or a base64-encoded string with a
+.Dq base64:
+prefix.
+For example:
+.Bd -literal -offset 4n
+TLS_KEYPW base64:dGVzdA==
+.Ed
+.Pp
+If a plain text password is used, it should be a simple string without quotes.
+Plain text passwords may not include the comment character
 .Pq Ql #
-and escaping of special characters with a backslash
+and the escaping of special characters with a backslash
 .Pq Ql \e
 is not supported.
 If this option is used,
index 8c636af0afc479f2f255f9aa8a47ee50c5d5f38a..59d9f1d9e258da5231f504614b76dc77f2a9c73e 100644 (file)
@@ -1381,20 +1381,48 @@ sudo_ldap_build_pass2(void)
     debug_return_str(filt);
 }
 
+/*
+ * Decode a secret if it is base64 encoded, else return NULL.
+ */
+static char *
+sudo_ldap_decode_secret(const char *secret)
+{
+    char *result = NULL;
+    size_t len, reslen;
+    debug_decl(sudo_ldap_decode_secret, SUDO_DEBUG_LDAP)
+
+    if (strncasecmp(secret, "base64:", sizeof("base64:") - 1) == 0) {
+       /*
+        * Decode a base64 secret.  The decoded length is 3/4 the encoded
+        * length but padding may be missing so round up to a multiple of 4.
+        */
+       secret += sizeof("base64:") - 1;
+       reslen = ((strlen(secret) + 3) / 4 * 3) + 1;
+       result = sudo_emalloc(reslen);
+       len = base64_decode(secret, result, reslen);
+       if (len == (size_t)-1) {
+           free(result);
+           result = NULL;
+       }
+    }
+    debug_return_str(result);
+}
+
 static void
 sudo_ldap_read_secret(const char *path)
 {
     FILE *fp;
-    char buf[LINE_MAX], *cp;
+    char buf[LINE_MAX];
     debug_decl(sudo_ldap_read_secret, SUDO_DEBUG_LDAP)
 
     if ((fp = fopen(path_ldap_secret, "r")) != NULL) {
        if (fgets(buf, sizeof(buf), fp) != NULL) {
-           if ((cp = strchr(buf, '\n')) != NULL)
-               *cp = '\0';
+           buf[strcspn(buf, "\n")] = '\0';
            /* copy to bindpw and binddn */
            efree(ldap_conf.bindpw);
-           ldap_conf.bindpw = sudo_estrdup(buf);
+           ldap_conf.bindpw = sudo_ldap_decode_secret(buf);
+           if (ldap_conf.bindpw == NULL)
+               ldap_conf.bindpw = sudo_estrdup(buf);
            efree(ldap_conf.binddn);
            ldap_conf.binddn = ldap_conf.rootbinddn;
            ldap_conf.rootbinddn = NULL;
@@ -1718,9 +1746,25 @@ sudo_ldap_read_config(void)
        efree(cp);
     }
 
+
     /* If rootbinddn set, read in /etc/ldap.secret if it exists. */
-    if (ldap_conf.rootbinddn)
+    if (ldap_conf.rootbinddn) {
        sudo_ldap_read_secret(path_ldap_secret);
+    } else if (ldap_conf.bindpw) {
+       cp = sudo_ldap_decode_secret(ldap_conf.bindpw);
+       if (cp != NULL) {
+           efree(ldap_conf.bindpw);
+           ldap_conf.bindpw = cp;
+       }
+    }
+
+    if (ldap_conf.tls_keypw) {
+       cp = sudo_ldap_decode_secret(ldap_conf.tls_keypw);
+       if (cp != NULL) {
+           efree(ldap_conf.tls_keypw);
+           ldap_conf.tls_keypw = cp;
+       }
+    }
 
 #ifdef HAVE_LDAP_SASL_INTERACTIVE_BIND_S
     /*