Git Product home page Git Product logo

perfect-spnego's Introduction

Perfect-SPNEGO 简体中文

Get Involed with Perfect!

Star Perfect On Github Stack Overflow Follow Perfect on Twitter Join the Perfect Slack

Swift 3.0 Platforms OS X | Linux License Apache PerfectlySoft Twitter Slack Status

This project provides a general server library which provides SPNEGO mechanism.

This package builds with Swift Package Manager and is part of the Perfect project.

Ensure you have installed and activated the latest Swift 3.0 tool chain.

Before Start

Perfect SPNEGO is aiming on a general application of Server Side Swift, so it could be plugged into ANY servers, such as HTTP / FTP / SSH, etc.

Although it supports Perfect HTTP server natively, it could be applied to any other Swift servers as well.

Before attaching to any actual server applications, please make sure your server has been already configured with Kerberos V5.

Xcode Build Note

If you would like to use Xcode to build this project, please make sure to pass proper linker flags to the Swift Package Manager:

$ swift package -Xlinker -framework -Xlinker GSS generate-xcodeproj

Linux Build Note

A special library called libkrb5-dev is required to build this project:

$ sudo apt-get install libkrb5-dev

If your server is a KDC, then you can skip this step, otherwise please install Kerberos V5 utilities:

$ sudo apt-get install krb5-user

KDC Configuration

Configure the application server's /etc/krb5.conf to your KDC. The following sample configuration shows how to connect your application server to realm KRB5.CA under control of a KDC named nut.krb5.ca:

[realms]
KRB5.CA = {
	kdc = nut.krb5.ca
	admin_server = nut.krb5.ca
}
[domain_realm]
.krb5.ca = KRB5.CA
krb5.ca = KRB5.CA

Prepare Kerberos Keys for Server

Contact to your KDC administrator to assign a keytab file to your application server.

Take example, SUPPOSE ALL HOSTS BELOW REGISTERED ON THE SAME DNS SERVER:

  • KDC server: nut.krb5.ca
  • Application server: coco.krb5.ca
  • Application server type: HTTP

In such a case, KDC administrator shall login on nut.krb5.ca then perform following operation:

kadmin.local: addprinc -randkey HTTP/[email protected]
kadmin.local: ktadd -k /tmp/krb5.keytab HTTP/[email protected]

Then please ship this krb5.keytab file securely and install on your application server coco.krb5.ca and move to folder /etc, then grant sufficient permissions to your swift application to access it.

Quick Start

Add the following dependency to your project's Package.swift file:

.Package(url: "https://github.com/PerfectlySoft/Perfect-SPNEGO.git", majorVersion: 1)

Then import Perfect-SPNEGO to your source code:

import PerfectSPNEGO

Connect to KDC

Use the key in your default keytab /etc/krb5.keytab file on application server to register your application server to the KDC.

let spnego = try Spnego("[email protected]")

Please note that the host name and protocol type MUST match the records listed in the keytab file.

Respond to A Spnego Challenge

Once initialized, object spnego could respond to the challenges. Take example, if a user is trying to connect to the application server as:

$ kinit [email protected]
$ curl --negotiate -u : http://coco.krb5.ca

In this case, the curl command would possibly send a base64 encoded challenge in the HTTP header:

> Authorization: Negotiate YIICnQYGKwYBBQUCoIICkTCCAo2gJzAlBgkqhkiG9xIBAgI ...

Once received such a challenge, you could apply this base64 string to the spnego object:

let (user, response) = try spnego.accept(base64Token: "YIICnQYGKwYBBQUCoIICkTCCAo2gJzAlBgkqhkiG9xIBAgI...")

If succeeded, the user would be "[email protected]". The variable response might be nil which indicates nothing is required to reply such a token, otherwise you should send this response back to the client.

Up till now, your application had already got the user information and request, then the application server might decide if this user could access the objective resource or not, according to your ACL (access control list) configuration.

Further Information

For more information on the Perfect project, please visit perfect.org.

Acknowledgement

For rapid development purposes, this repo includes an base64 implementation developed by Sean Starkey [email protected] but it is subject to Perfect's future development. https://github.com/SeanStarkey/base64

perfect-spnego's People

Contributors

kjessup avatar rockfordwei avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

Forkers

isabella232

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.