All Projects → torinkwok → WaxSealCore

torinkwok / WaxSealCore

Licence: other
Simple, expressive yet comprehensive keychain wrapper in Objective-C.

Programming Languages

objective c
16641 projects - #2 most used programming language
Roff
2310 projects

Projects that are alternatives of or similar to WaxSealCore

fortify
Fortify enables web applications to use smart cards, local certificate stores and do certificate enrollment. This is the desktop application repository.
Stars: ✭ 88 (+166.67%)
Mutual labels:  certificate, keychain
Ptero4J
A java wrapper for the pterodactyl panel API
Stars: ✭ 26 (-21.21%)
Mutual labels:  wrapper
with-wrapper
React HOC for wrapper components.
Stars: ✭ 35 (+6.06%)
Mutual labels:  wrapper
node-api
A JavaScript API Wrapper for NovelCOVID/API
Stars: ✭ 63 (+90.91%)
Mutual labels:  wrapper
diceware
Improved diceware passphrases
Stars: ✭ 16 (-51.52%)
Mutual labels:  passphrase
CertificateDsc
DSC resources to simplify administration of certificates on a Windows Server.
Stars: ✭ 103 (+212.12%)
Mutual labels:  certificate
service-identity
Service Identity Verification for Python
Stars: ✭ 78 (+136.36%)
Mutual labels:  certificate
KeychainWrapper
A lightweight, pure-Swift library for the iOS keychain.
Stars: ✭ 51 (+54.55%)
Mutual labels:  keychain
Taviloglu.Wrike.ApiClient
.NET Client for Wrike API
Stars: ✭ 24 (-27.27%)
Mutual labels:  wrapper
Mega-index-heroku
Mega nz heroku index, Serves mega.nz to http via heroku web. It Alters downloading speed and stability
Stars: ✭ 165 (+400%)
Mutual labels:  wrapper
kucero
KUbernetes CErtificate ROtation
Stars: ✭ 27 (-18.18%)
Mutual labels:  certificate
uniswap-python
🦄 The unofficial Python client for the Uniswap exchange.
Stars: ✭ 533 (+1515.15%)
Mutual labels:  wrapper
MangaDex.py
An easy to use wrapper for the MangaDexAPIv5 written in Python using Requests.
Stars: ✭ 13 (-60.61%)
Mutual labels:  wrapper
RT-Thread-wrapper-of-uCOS-II
RT-Thread操作系统的uCOS-II兼容层:让基于uC/OS-II操作系统开发的应用层无感地迁移到RT-Thread操作系统 | A wrapper which can make codes developed by uCOS-II APIs directly run on RT-Thread
Stars: ✭ 24 (-27.27%)
Mutual labels:  wrapper
spmf-py
Python SPMF Wrapper 🐍 🎁
Stars: ✭ 35 (+6.06%)
Mutual labels:  wrapper
SharpPhysFS
Managed wrapper for the PhysFS library
Stars: ✭ 14 (-57.58%)
Mutual labels:  wrapper
fireREST
Python library for interacting with Cisco Firepower Management Center REST API
Stars: ✭ 47 (+42.42%)
Mutual labels:  wrapper
WireGuard-Wrapper
Simple wrapper that makes WireGuard easier to use with VPN providers.
Stars: ✭ 29 (-12.12%)
Mutual labels:  wrapper
GoAnimate-Wrapper
GoAPI server wrapper designed to interact with Vyond's Legacy Video Maker (written in Node.JS)
Stars: ✭ 22 (-33.33%)
Mutual labels:  wrapper
gsh
GSH is an OpenID Connect-compatible authentication system for systems using OpenSSH servers
Stars: ✭ 21 (-36.36%)
Mutual labels:  certificate

WaxSealCore Gitter

What's New in This Version (v2.0.1)

  • Solved the percent escapes problem of URL property for WSCKeychain

What's WaxSealCore

WaxSealCore is a modern and full feature Objective-C wrapper for Keychain Services and Certificate, Key, and Trust Services that works on Mac.

Why WaxSealCore

Computer users typically have to manage multiple accounts that require logins with user IDs and passwords. Secure FTP servers, database servers, secure websites, instant messaging accounts, and many other services require authentication before they can be used. Users often respond to this situation by making up very simple, easily remembered passwords, by using the same password over and over, or by writing passwords down where they can be easily found. Any of these cases compromises security.

The Keychain Services API provides a solution to this problem. By making a single call to this API, an application can store login information on a keychain where the application can retrieve the information—also with a single call—when needed. A keychain is an encrypted container that holds passwords for multiple applications and secure services. Keychains are secure storage containers, which means that when the keychain is locked, no one can access its protected contents. In OS X, users can unlock a keychain—thus providing trusted applications access to the contents—by entering a single master password.

Keychain Services is powerful, HOWEVER:

  • Keychain Services's API is pure C, it's very ugly and hard to use
  • Keychain Services doesn't support Unicode
  • Keychain Services is based on Core Foundation, so you have to manage memory manually
  • The Apple official documentation of Keychain Services is old and riddled with errors

we need a OOP wrapper of this API to make life easier. There are some repos about this, like EMKeychain and SSKeychain. I admit, they are cool. But they aren't full feature (in other words, too simple). We need a full feature wrapper of Keychain Services which can create and delete a keychain or passphrase item quickly, while can also take advantage of the advanced feature of Keychain Services such as Access Control List. Therefore, I wrote WaxSealCore.

Keychain Services vs. WaxSealCore

Create an empty keychain with given passphrase:

  • using pure C API of Keychain Services:
OSStatus resultCode = errSecSuccess;
SecKeychainRef secEmptyKeychain = NULL;

NSURL* URL = [ [ [ NSBundle mainBundle ] bundleURL ]
  URLByAppendingPathComponent: @"EmptyKeychainForWiki.keychain" ];

char* passphrase = "waxsealcore";

// Create an empty keychain with given passphrase
resultCode = SecKeychainCreate( 
    URL.path.UTF8String
  , ( UInt32 )strlen( passphrase )
  , ( void const* )passphrase
  , ( Boolean )NO
  , NULL
  , &secEmptyKeychain
  );

NSAssert( resultCode == errSecSuccess, @"Failed to create new empty keychain" );

resultCode = SecKeychainDelete( secEmptyKeychain );
NSAssert( resultCode == errSecSuccess, @"Failed to delete the given keychain" );

if ( secEmptyKeychain ) {
  // Keychain Services is based on Core Foundation,
  // you have to manage the memory manually
  CFRelease( secEmptyKeychain );
  }
  • using WaxSealCore:
NSError* error = nil;

// Create an empty keychain with given passphrase
WSCKeychain* emptyKeychain = [ [ WSCKeychainManager defaultManager ]
  createKeychainWithURL: [ [ [ NSBundle mainBundle ] bundleURL ]
    URLByAppendingPathComponent: @"EmptyKeychainForWiki.keychain" ]
      passphrase: @"waxsealcore"
  becomesDefault: NO
           error: &error ];

// You have no need for managing the memory manually,
// emptyKeychain will be released automatically.

Find the following Internet passphrase then print its Account Name, Passphrase and Comment

  • using pure C API of Keychain Services (OMG. Give me a break😲🔫):
>OSStatus resultCode = errSecSuccess;

// Attributes that will be used for constructing search criteria
char* label = "secure.imdb.com";
SecProtocolType* ptrProtocolType = malloc( sizeof( SecProtocolType ) );
*ptrProtocolType = kSecProtocolTypeHTTPS;

SecKeychainAttribute attrs[] =
  { { kSecLabelItemAttr, ( UInt32 )strlen( label ), ( void* )label }
  , { kSecProtocolItemAttr, ( UInt32 )sizeof( SecProtocolType ), ( void* )ptrProtocolType }
  };

SecKeychainAttributeList attrsList = { sizeof( attrs ) / sizeof( attrs[ 0 ] ), attrs };

// Creates a search object matching the given list of search criteria.
SecKeychainSearchRef searchObject = NULL;
if ( ( resultCode = SecKeychainSearchCreateFromAttributes(
    NULL
  , kSecInternetPasswordItemClass
  , &attrsList
  , &searchObject ) ) == errSecSuccess ) {
  SecKeychainItemRef matchedItem = NULL;

  // Finds the next keychain item matching the given search criteria.
  while ( ( resultCode = SecKeychainSearchCopyNext( searchObject, &matchedItem ) ) != errSecItemNotFound ) {
    SecKeychainAttribute theAttributes[] = 
      { { kSecAccountItemAttr, 0, NULL }
      , { kSecCommentItemAttr, 0, NULL }
      };

    SecKeychainAttributeList theAttrList =
      { sizeof( theAttributes ) / sizeof( theAttributes[ 0 ] )
      , theAttributes
      };

    UInt32 lengthOfPassphrase = 0;
    char* passphraseBuffer = NULL;
    if ( ( resultCode = SecKeychainItemCopyContent(
        matchedItem
      , NULL
      , &theAttrList
      , &lengthOfPassphrase
      , ( void** )&passphraseBuffer ) ) == errSecSuccess ) {
        NSLog( @"\n==============================\n" );

        NSLog( @"Passphrase: %@", [ [ [ NSString alloc ]
          initWithBytes: passphraseBuffer
                 length: lengthOfPassphrase
               encoding: NSUTF8StringEncoding ] autorelease ] );

        for ( int _Index = 0; _Index < theAttrList.count; _Index++ ) {
          SecKeychainAttribute attrStruct = theAttrList.attr[ _Index ];
          NSString* attributeValue =
            [ [ [ NSString alloc ]
                initWithBytes: attrStruct.data
                       length: attrStruct.length
                     encoding: NSUTF8StringEncoding ] autorelease ];

          if ( attrStruct.tag == kSecAccountItemAttr )
            NSLog( @"IMDb User Name: %@", attributeValue );
          else if ( attrStruct.tag == kSecCommentItemAttr )
            NSLog( @"Comment: %@", attributeValue );
          }

        NSLog( @"\n==============================\n" );
        }

    SecKeychainItemFreeContent( &theAttrList, passphraseBuffer );
    CFRelease( matchedItem );
    }
 }

if ( ptrProtocolType ) {
  free( ptrProtocolType );
  }

if ( searchObject ) {
  CFRelease( searchObject );
  }
  • using WaxSealCore (Just a few lines of Objective-C code):
NSError* error = nil;

WSCPassphraseItem* IMDbLoginPassphrase =
  ( WSCPassphraseItem* )[ [ WSCKeychain login ]
  findFirstKeychainItemSatisfyingSearchCriteria:
    @{ WSCKeychainItemAttributeLabel : @"secure.imdb.com"
     , WSCKeychainItemAttributeProtocol : WSCInternetProtocolCocoaValue( WSCInternetProtocolTypeHTTPS )
     , WSCKeychainItemAttributeComment : @"👺👹👺👹"
     }
  itemClass: WSCKeychainItemClassInternetPassphraseItem
      error: &error ];
                                            
// WaxSealCore supports Unicode-based search, 
// so you can use Emoji or Chinese in your search criteria.
// One step. Quite handy, isn't it?

Print its Account Name, Passphrase and Comment:

if ( IMDbLoginPassphrase ) {
  NSLog( @"==============================" );
  // Use the `account` property
  NSLog( @"IMDb User Name: %@", IMDbLoginPassphrase.account );

  // Use the `passphrase` property
  NSLog( @"Passphrase: %@", [ [ [ NSString alloc ] initWithData: IMDbLoginPassphrase.passphrase encoding: NSUTF8StringEncoding ] autorelease ] );

  // Use the `comment` property
  NSLog( @"Comment: %@", IMDbLoginPassphrase.comment );
  NSLog( @"==============================" );

  // -setComment:
  IMDbLoginPassphrase.comment = @"👿👿👿👿👿👿";
 } else {
   NSLog( @"I'm so sorry!" );
   }

Batch Search:

// Find all the Internet passphrases that met the given search criteria
NSArray* passphrases = [ [ WSCKeychain login ]
    // Batch search
    findAllKeychainItemsSatisfyingSearchCriteria: @{ WSCKeychainItemAttributeLabel : @"secure.imdb.com"
                                                   , WSCKeychainItemAttributeProtocol : WSCInternetProtocolCocoaValue( WSCInternetProtocolTypeHTTPS )
                                                   , WSCKeychainItemAttributeComment : @"👿👿👿👿👿👿"
                                                   }
                                       itemClass: WSCKeychainItemClassInternetPassphraseItem
                                           error: &error ];
if ( passphrases.count != 0 )
    {
    for ( WSCPassphraseItem* _Passphrase in passphrases )
        {
        NSLog( @"==============================" );
        NSLog( @"IMDb User Name: %@", IMDbLoginPassphrase.account );
        NSLog( @"Passphrase: %@", [ [ [ NSString alloc ] initWithData: IMDbLoginPassphrase.passphrase encoding: NSUTF8StringEncoding ] autorelease ] );
        NSLog( @"Comment: %@", IMDbLoginPassphrase.comment );
        NSLog( @"==============================" );

        _Passphrase.comment = @"👺👹👺👹";
        }
    }
else
    NSLog( @"I'm so sorry!" );

Documentation

Minimum System Requirements

  • Xcode 5.x or greater for compiling

  • OS X 10.7 for compiling and running

Contact Me

If you encounter any issue, you can:

  • Email me: dG9uZy1rdW9Ab3V0bG9vay5jb20= (Base64ed)
  • DM me on Twitter: @NSTongK
  • If you are using S/MIME, you can send me encrypted email by retrieving my S/MIME certificate and its related intermediate certificates in here
  • If you are using GnuPG, you can send me encrypted email, my GnuPG pub key is 0x5604FA90, you can retrieve it from keyserver.

License

Copyright (c) 2015 Tong Kuo

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].