pax_global_header 0000666 0000000 0000000 00000000064 12303044756 0014516 g ustar 00root root 0000000 0000000 52 comment=66b37b16d8c29072c16a8c2c8d4a53256a67bcdb
mod_authnz_persona-0.8.1/ 0000775 0000000 0000000 00000000000 12303044756 0015423 5 ustar 00root root 0000000 0000000 mod_authnz_persona-0.8.1/.gitignore 0000664 0000000 0000000 00000000012 12303044756 0017404 0 ustar 00root root 0000000 0000000 /build
*~
mod_authnz_persona-0.8.1/COPYING 0000664 0000000 0000000 00000026135 12303044756 0016465 0 ustar 00root root 0000000 0000000 Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "{}"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright {yyyy} {name of copyright owner}
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
mod_authnz_persona-0.8.1/Makefile 0000664 0000000 0000000 00000002340 12303044756 0017062 0 ustar 00root root 0000000 0000000 ifeq ($(APXS_PATH),)
APXS_PATH=/usr/sbin/apxs
endif
MY_LDFLAGS=-lcurl -lyajl
# Note that gcc flags are passed through apxs, so preface with -Wc
MY_CFLAGS=-Wc,-I. -Wc,-Wall -Wc,-g -Wc,-Wno-unused-function
SRCS=src/mod_authnz_persona.c src/cookie.c src/verify.c src/hmac.c
HDRS=src/cookie.h src/defines.h src/verify.h src/hmac.h
BUILDDIR := build
.SUFFIXES: .c .o .la
all: build/.libs/mod_authnz_persona.so
.PHONY: builddir
builddir: build
$(BUILDDIR):
@mkdir -p $@
$(BUILDDIR)/bin2c: tools/bin2c.c | $(BUILDDIR)
@gcc -Wall -g -o $(BUILDDIR)/bin2c $<
$(BUILDDIR)/signin_page.h: src/signin.html $(BUILDDIR)/bin2c | $(BUILDDIR)
@$(BUILDDIR)/bin2c $^ > $@
$(BUILDDIR)/error.html: src/error.html src/signin.html
@cp src/signin.html $@
@cat src/error.html >> $@
$(BUILDDIR)/error_page.h: $(BUILDDIR)/error.html $(BUILDDIR)/bin2c | $(BUILDDIR)
@$(BUILDDIR)/bin2c $^ > $@
$(BUILDDIR)/.libs/mod_authnz_persona.so: $(SRCS) $(HDRS) $(BUILDDIR)/signin_page.h $(BUILDDIR)/error_page.h
@cd $(BUILDDIR) && for file in $(SRCS) $(HDRS) ; do ln -sf ../$$file . ; done
@cd $(BUILDDIR) && $(APXS_PATH) $(MY_LDFLAGS) $(MY_CFLAGS) -c $(subst src/,,$(SRCS))
install: all
$(APXS_PATH) -i $(BUILDDIR)/mod_authnz_persona.la
clean:
-rm -rf $(BUILDDIR)
mod_authnz_persona-0.8.1/README.md 0000664 0000000 0000000 00000006453 12303044756 0016712 0 ustar 00root root 0000000 0000000 mod_authnz_persona is a module for Apache 2.0 or later that allows you to
quickly add Persona authentication to a site hosted with Apache.
# Installation
First, install the dependencies:
* apache 2.2 or later
* libcurl 7.10.8 or later (for remote verification)
* yajl 2.0 or later (for JSON parsing)
On Red Hat-derivative distributions, this might help:
```
yum install httpd httpd-devel curl-devel cmake
wget http://fedora.mirror.nexicom.net/linux/development/rawhide/source/SRPMS/y/yajl-2.0.4-3.fc20.src.rpm
rpmbuild --rebuild yajl-*.src.rpm
sudo yum install ~/rpmbuild/RPMS/`uname -i`/yajl-*.rpm
```
(CMake is a build-time yajl dependency.)
Then, clone the source and build:
```
git clone https://github.com/mozilla/mod_authnz_persona.git
cd mod_authnz_persona
make
sudo make install
```
(This assumes apxs is behaving properly on your system; set the
APXS_PATH variable to your apxs or apxs2 as appropriate.)
# Configuration
Configure the module:
LoadModule authnz_persona_module modules/mod_authnz_persona.so
AuthType Persona
Require valid-user
# Or, require users with host/IdP example.com:
# Require persona-idp example.com
# Or, require specific users (requires mod_authz_user)
# Require user user@example.com
This will cause the module to require Persona authentication for all requests
to the server.
# Features
* **zero configuration** - The module is designed with reasonable defaults, so
you can simply drop it in.
* **automatic re-auth** - The module is designed to use session cookies and
automatically re-authenticate.
# How it works
The module works by intercepting requests bound for protected resources, and
checking for the presence of a session cookie.
If the cookie is not found, the user agent is served an HTML document that
presents a Persona login page.
Upon successful authentication with Persona, this page will send a request to
the server with a Persona assertion in an HTTP header. The module, upon
detecting no cookie is present, will look for this header, validate the
assertion, and set a short session cookie.
The authentication page will then reload the desired resource.
# Further configuration settings
* `AuthPersonaServerSecret`:
A secret that will be used to sign cookies. Must be set in a server or
VirtualHost context. If not provided, upon server start a secret will be
generated automatically. Given re-authentication is automatic, it is only
required to set a cookie secret if your application is hosted on multiple
load-balanced Apache servers.
* `AuthPersonaLogoutPath`:
A path that can be linked to for logout. Relative to the server root; must
start with a `/` to match. If this is enabled, users can be logged out by
linking to the URL set up by this option. After logout, the user will be
redirected to the full URL passed in the `returnto` query string argument, if
available; if not, the user will be redirected to `/` (which can be
confusing, due to automatic re-authentication).
* `Require persona-idp`:
Only allow users with email addresses backed by the given Identity Provider.
Note that this will often, but not necessarily, be the host part of the
verified email address, in the case of email addresses backed by a secondary
IdP (like the fallback IdP or a bridging IdP).
mod_authnz_persona-0.8.1/src/ 0000775 0000000 0000000 00000000000 12303044756 0016212 5 ustar 00root root 0000000 0000000 mod_authnz_persona-0.8.1/src/cookie.c 0000664 0000000 0000000 00000012737 12303044756 0017641 0 ustar 00root root 0000000 0000000 /* Copyright 1999-2014 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* Based in part, on mod_auth_memcookie, made by Mathieu CARBONNEAUX.
*
* See http://authmemcookie.sourceforge.net/ for details;
* licensed under Apache License, Version 2.0.
*
* SHA-1 implementation by Steve Reid, steve@edmweb.com, in
* public domain.
*/
#include
#include
#include
#include
#include
#include
#include
#include
#include "cookie.h"
#include "defines.h"
#include "hmac.h"
/** Generates a HMAC with the given inputs, returning a Base64-encoded
* signature value. */
static char *generateHMAC(request_rec *r, const buffer_t *secret, const Cookie cookie)
{
char *data;
unsigned char digest[HMAC_DIGESTSIZE];
char *digest64;
char timestr[12];
snprintf(timestr, 12, "%" APR_TIME_T_FMT, cookie->created);
data = apr_pstrcat(r->pool, cookie->verifiedEmail, cookie->identityIssuer, timestr, NULL);
hmac(secret->data, secret->len, data, strlen(data), &digest);
digest64 = apr_palloc(r->pool, apr_base64_encode_len(HMAC_DIGESTSIZE));
apr_base64_encode(digest64, (char*)digest, HMAC_DIGESTSIZE);
return digest64;
}
/* Look through the 'Cookie' headers for the indicated cookie; extract it
* and URL-unescape it. Return the cookie on success, NULL on failure. */
char * extractCookie(request_rec *r, const buffer_t *secret, const char *szCookie_name)
{
char *szRaw_cookie_start=NULL, *szRaw_cookie_end;
char *szCookie;
/* get cookie string */
char*szRaw_cookie = (char*)apr_table_get( r->headers_in, "Cookie");
if (!szRaw_cookie) return 0;
/* loop to search cookie name in cookie header */
do {
ap_log_rerror(APLOG_MARK, APLOG_DEBUG|APLOG_NOERRNO, 0, r, ERRTAG "Checking cookie %s, looking for %s", szRaw_cookie, szCookie_name);
/* search cookie name in cookie string */
if (!(szRaw_cookie = strstr(szRaw_cookie, szCookie_name))) return 0;
szRaw_cookie_start=szRaw_cookie;
/* search '=' */
if (!(szRaw_cookie = strchr(szRaw_cookie, '='))) return 0;
} while (strncmp(szCookie_name,szRaw_cookie_start,szRaw_cookie-szRaw_cookie_start)!=0);
/* skip '=' */
szRaw_cookie++;
/* search end of cookie name value: ';' or end of cookie strings */
if (!((szRaw_cookie_end = strchr(szRaw_cookie, ';')) || (szRaw_cookie_end = strchr(szRaw_cookie, '\0')))) return 0;
/* dup the value string found in apache pool and set the result pool ptr to szCookie ptr */
if (!(szCookie = apr_pstrndup(r->pool, szRaw_cookie, szRaw_cookie_end-szRaw_cookie))) return 0;
/* unescape the value string */
if (ap_unescape_url(szCookie) != 0) return 0;
ap_log_rerror(APLOG_MARK, APLOG_DEBUG|APLOG_NOERRNO, 0, r, ERRTAG "finished cookie scan, returning %s", szCookie);
return szCookie;
}
/* Check the cookie and make sure it is valid */
Cookie validateCookie(request_rec *r, const buffer_t *secret, const char *szCookieValue)
{
/* split at | */
char *iss = NULL;
char *sig = NULL;
char *crea = NULL;
char *addr = apr_strtok((char *) szCookieValue, "|", &iss);
if (!addr) {
ap_log_rerror(APLOG_MARK, APLOG_ERR|APLOG_NOERRNO, 0, r, ERRTAG "malformed Persona cookie, can't extract email");
return NULL;
}
iss = apr_strtok((char *) iss, "|", &crea);
if (!iss) {
ap_log_rerror(APLOG_MARK, APLOG_ERR|APLOG_NOERRNO, 0, r, ERRTAG "malformed Persona cookie, can't extract issuer");
return NULL;
}
crea = apr_strtok((char *) crea, "|", &sig);
if (!crea) {
ap_log_rerror(APLOG_MARK, APLOG_ERR|APLOG_NOERRNO, 0, r, ERRTAG "malformed Persona cookie, can't extract time");
return NULL;
}
Cookie c = apr_pcalloc(r->pool, sizeof(struct _Cookie));
c->verifiedEmail = addr;
c->identityIssuer = iss;
c->created = strtol(crea, NULL, 10);
char *digest64 = generateHMAC(r, secret, c);
ap_log_rerror(APLOG_MARK, APLOG_DEBUG|APLOG_NOERRNO, 0, r, ERRTAG "Got cookie: email is %s; expected digest is %s; got digest %s",
addr, digest64, sig);
/* paranoia indicates that we should use a time-invariant compare here */
if (strcmp(digest64, sig)) {
ap_log_rerror(APLOG_MARK, APLOG_ERR|APLOG_NOERRNO, 0, r, ERRTAG "invalid Persona cookie");
return NULL;
}
return c;
}
/** Create a session cookie with a given identity */
void sendSignedCookie(request_rec *r, const buffer_t *secret, const Cookie cookie)
{
char *digest64 = generateHMAC(r, secret, cookie);
/* syntax of cookie is identity|issuer|timestamp|signature */
apr_table_set(r->err_headers_out, "Set-Cookie",
apr_psprintf(r->pool, "%s=%s|%s|%" APR_TIME_T_FMT "|%s; Path=/",
PERSONA_COOKIE_NAME, cookie->verifiedEmail,
cookie->identityIssuer, cookie->created, digest64));
}
void sendResetCookie(request_rec *r) {
apr_table_set(r->err_headers_out, "Set-Cookie",
apr_psprintf(r->pool, "%s=; Path=/; Expires=Thu, 01-Jan-1970 00:00:01 GMT",
PERSONA_COOKIE_NAME));
}
mod_authnz_persona-0.8.1/src/cookie.h 0000664 0000000 0000000 00000003033 12303044756 0017633 0 ustar 00root root 0000000 0000000 /* Copyright 1999-2014 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* Cookie management routines
*/
#ifndef __COOKIE_H__
#define __COOKIE_H__
#include
#include "defines.h"
typedef struct _Cookie {
const char *verifiedEmail; // email that was verified
const char *identityIssuer; // domain that issued the identity
apr_time_t created; // when this cookie was created
}* Cookie;
/* Look through the 'Cookie' headers for the indicated cookie; extract it
* and URL-unescape it. Return the cookie on success, NULL on failure. */
char * extractCookie(request_rec *r, const buffer_t *secret, const char *szCookie_name);
/* Check the cookie and make sure it is valid */
Cookie validateCookie(request_rec *r, const buffer_t *secret, const char *szCookieValue);
/** Create a session cookie with a given identity */
void sendSignedCookie(request_rec *r, const buffer_t *secret, const Cookie cookie);
/* Send an empty cookie, to reset the session */
void sendResetCookie(request_rec *r);
#endif
mod_authnz_persona-0.8.1/src/defines.h 0000664 0000000 0000000 00000002306 12303044756 0020001 0 ustar 00root root 0000000 0000000 /* Copyright 1999-2014 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef __DEFINES_H__
#define __DEFINES_H__
#include
#define PERSONA_DEFAULT_VERIFIER_URL "https://verifier.login.persona.org/verify"
#define PERSONA_COOKIE_NAME "Persona"
#define PERSONA_ISSUER_NOTE "persona-identity-issuer"
#define PERSONA_SECRET_SIZE 1024
#define PERSONA_ASSERTION_HEADER "Persona-Assertion"
#define PERSONA_END_PAGE "\n\n