Coder Social home page Coder Social logo

carbon-crypto-service's Introduction

Carbon Crypto Service

Carbon Crypto Service is a configurable framework to cater crypto needs in Carbon products. In a software all the crypto needs can be put in to two categories.

  1. Handling data encryption for storing. i.e. internal crypto needs

  2. Using cryptography when dealing with external parties. i.e. external crypto needs.

The Carbon Crypto Service provides an extensible way to cater these two categories.

Concepts

  1. Internal crypto provider

    The component which deals with data encryption and decryption for internal usage. e.g. storing

  2. External crypto provider

    The component which deals with the signing, signature validation, encryption, decryption when working with external entities.

  3. Crypto context

    One of the main purposes of the crypto service is to provide a developer friendly API to handle cryptography in Carbon product. The crypto context helps the developers to write the context specific logic (e.g. Finding the public key of the external party for validating the signature) once is re-use it by just passing the context for operation.

    verifySignature(data, signature, algorithm, javaSecurityAPIProvider, cryptoContext);
    
  4. Key resolver chain

    In external crypto scenarios the keys of the external entities (i.e. public keys) might be stored in different places. e.g. Databases, KeyStores. Key resolver chains find the applicable key information based on the crypto context.

The default implementations

  1. Default internal crypto provider

    The default internal crypto provider is based on asymmetric cryptography due to historical reasons. This implementation reads the needed Java KeyStore information from a configuration file. More details can be found in the How to use section. The crypto service ships a symmetric key based internal crypto provider as well. But it is not the default implementation.

  2. Default external crypto provider

    The crypto service doesn't ship a default external crypto provider. The external crypto operations in Carbon products should deal with the complexity behind tenant key stores etc. which is outside the crypto service's scope. Therefore the Carbon Kernel ships an implementation to be used in Carbon products. For the sake of completeness that implementation also will be mentioned in this documentation whenever needed.

  3. Default key resolver

    A context independent key resolver is shipped to be used as the last resort to resolve the needed key information for the given context. Since the key resolvers has a priority mechanism, if an applicable resolver is found for a context, the default resolver won't be used.

How to use

  1. Configure

    Below is the default configuration block for the crypto service. For the crypto service to work, a valid configuration block should be there in repository/conf/carbon.xml.

    <CryptoService>
      <Enabled>true</Enabled>
      <InternalCryptoProviderClassName>org.wso2.carbon.crypto.provider.KeyStoreBasedInternalCryptoProvider</InternalCryptoProviderClassName>
      <ExternalCryptoProviderClassName>org.wso2.carbon.core.encryption.KeyStoreBasedExternalCryptoProvider</ExternalCryptoProviderClassName>
      <KeyResolvers>
        <KeyResolver className="org.wso2.carbon.crypto.defaultProvider.resolver.ContextIndependentKeyResolver" priority="-1"/>
      </KeyResolvers>
    </CryptoService>
    
    <Security>
      <InternalKeyStore>
        <Location>path_of_the_key_store</Location>
        <Type>JKS</Type>
        <Password>password_of_the_key_store</Password>
        <KeyAlias>alias_of_the_key</KeyAlias>
        <KeyPassword>password_of_the_key</KeyPassword>
      </InternalKeyStore>
    </Security>
    
  2. Invoke the API

    CryptoService cryptoService = // Get the implementation of the CryptoService using OSGi
    
    cryptoService.encrypt(plainTextBytes, algorithm, javaCryptoAPIProvider);
    
    

    All the available operations of the API are documented here.

Extension points

  1. Internal crypto provider

    Implement InternalCryptoProvider

  2. External crypto provider

    Implement ExternalCryptoProvider

  3. Key resolver

    Implement KeyResolver

  4. Crypto service

    Implement CryptoService

carbon-crypto-service's People

Contributors

ashensw avatar hasinidilanka avatar jkaushalya avatar madushadhanushka avatar maheshika avatar mevan-karu avatar rushmin avatar senthalan avatar tharindu1st avatar wso2-jenkins-bot avatar

Watchers

 avatar

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.