Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History

README.md

Outline

SecureMemory C# Edition

This class provides a way for applications to keep secret information (like cryptographic keys) in an area of memory that is secure in the described ways.

Version

Installation

You can get the latest release from Nuget:

<ItemGroup>
    <PackageReference Include="GoDaddy.Asherah.SecureMemory" Version="0.3.0" />
</ItemGroup>

Currently supported / tested platforms

  • MacOS x86-64
  • Linux x86-64
  • Windows x86-64

    Initial Windows support is provided primarily for local development

Configuration

Configuration Name Data type Values Default / Required Description
secureHeapEngine string openssl11, mmap Platform default (Usually mmap) Controls which secure heap implementation is used
heapSize ulong Size in bytes 32767 Size of the secure heap in bytes
minimumAllocationSize int Size in bytes 32 Minimum size of secure heap allocations
minimumWorkingSetSize ulong Size in bytes 33554430 Windows only: Configure the minimum working set size which influences how much memory can be VirtualLocked
maximumWorkingSetSize ulong Size in bytes 67108860 Windows only: Configure the maximum working set size which influences how much memory can be VirtualLocked

Quick Start

ISecretFactory secretFactory = new ProtectedMemorySecretFactory();

using (Secret secretKey = secretFactory.CreateSecret(secretBytes))
{
    secretKey.WithSecretBytes(bytes =>
    {
        DoSomethingWithSecretBytes(bytes);
    });
}

Goals

  • Provide an interface which allows safe patterns of secrets usage
  • Provide a handle for passing secrets around that doesn't expose the secret until it's actually used
  • Minimize the lifetime of secrets in managed memory

Guarantees

Any implementation must have the following guarantees in so far as secret information stored in secure memory

Linux/Mac:

  • Values stored will not show up in core dumps
  • Values stored will not be swapped
  • Values stored will be securely / explicitly zeroed out when no longer in use

Windows:

  • Values are encrypted in memory
  • Values stored will not be swapped
  • Values stored will be explicitly zeroed out when no longer in use

Secure Memory Implementation

This implementation of secure memory

  • Uses mprotect to mark the pages no-access until needed
  • If the operating system supports it, uses madvise to disallow core dumps of protected regions
  • If the operating system does not support madvise, uses setrlimit to disable core dumps entirely

Protected Memory Implementation

The protected memory implementation of secure memory

  • Uses mlock to lock the pages to prevent swapping
  • Uses mprotect to mark the pages no-access until needed
  • If the operating system supports it, uses madvise to disallow core dumps of protected regions
  • If the operating system does not support madvise, uses setrlimit to disable core dumps entirely

TODO

  • Add unit tests that generate core dumps and scan them for secrets (need to extract gcore source)
  • If the operating system supports it, uses madvise to request that mapped pages be zeroed on exit
Morty Proxy This is a proxified and sanitized view of the page, visit original site.