Skip to content

Commit

Permalink
Cleanup option passing to make it simpler to pass options around.
Browse files Browse the repository at this point in the history
Add new initialization vector setup mode for new filesystems.


git-svn-id: http://encfs.googlecode.com/svn/trunk@59 db9cf616-1c43-0410-9cb8-a902689de0d6
  • Loading branch information
vgough committed Aug 30, 2010
1 parent 460d040 commit 1707123
Show file tree
Hide file tree
Showing 24 changed files with 479 additions and 472 deletions.
10 changes: 10 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
Sun Aug 29 2010 Valient Gough <[email protected]>
* new IV initialization
* tag version 1.7

Sat Aug 28 2010 Valient Gough <[email protected]>
* fix component configuration to ease adding flags or config

Thu Jun 17 2010 Valient Gough <[email protected]>
* bump version to 1.6

Mon Jun 14 2010 Valient Gough <[email protected]>
* fix compile error for boost < 1.41 and change rWarning to rInfo
* fix compiler warnings about unused result from fgets
Expand Down
5 changes: 1 addition & 4 deletions configure.ac
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
dnl Process this file with autoconf to produce a configure script.

AC_INIT(encfs/encfs.h) dnl a source file from your sub dir
AM_INIT_AUTOMAKE(encfs, 1.5.1) dnl searches for some needed programs

RELEASE=1
AC_SUBST(RELEASE)
AM_INIT_AUTOMAKE(encfs, 1.7) dnl searches for some needed programs

AC_CANONICAL_HOST
AM_CONDITIONAL([DARWIN],
Expand Down
11 changes: 3 additions & 8 deletions encfs/BlockFileIO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ static void clearCache( IORequest &req, int blockSize )
req.dataLen = 0;
}

BlockFileIO::BlockFileIO( int dataSize )
: _blockSize( dataSize )
, _allowHoles( false )
BlockFileIO::BlockFileIO( int blockSize, const FSConfigPtr &cfg )
: _blockSize( blockSize )
, _allowHoles( cfg->config->allowHoles )
{
rAssert( _blockSize > 1 );
_cache.data = new unsigned char [ _blockSize ];
Expand Down Expand Up @@ -98,11 +98,6 @@ bool BlockFileIO::cacheWriteOneBlock( const IORequest &req )
return ok;
}

void BlockFileIO::allowHoles( bool allow )
{
_allowHoles = allow;
}

ssize_t BlockFileIO::read( const IORequest &req ) const
{
rAssert( _blockSize != 0 );
Expand Down
8 changes: 2 additions & 6 deletions encfs/BlockFileIO.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#define _BlockFileIO_incl_

#include "FileIO.h"
#include "FSConfig.h"

/*
Implements block scatter / gather interface. Requires derived classes to
Expand All @@ -31,7 +32,7 @@
class BlockFileIO : public FileIO
{
public:
BlockFileIO(int blockDataSize);
BlockFileIO( int blockSize, const FSConfigPtr &cfg );
virtual ~BlockFileIO();

// implemented in terms of blocks.
Expand All @@ -40,11 +41,6 @@ class BlockFileIO : public FileIO

virtual int blockSize() const;

// default is false, but setting this to true will allow holes to be stored
// in the file. Only works if supported by the underlying FileIO
// implementation..
virtual void allowHoles( bool allow );

protected:

int truncate( off_t size, FileIO *base );
Expand Down
41 changes: 20 additions & 21 deletions encfs/CipherFileIO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,23 +50,23 @@ static bool checkSize( int fsBlockSize, int cipherBlockSize )
}

CipherFileIO::CipherFileIO( const shared_ptr<FileIO> &_base,
const shared_ptr<Cipher> &_cipher,
const CipherKey &_key, int fsBlockSize,
bool uniqueIV, bool _reverseEncryption )
: BlockFileIO( fsBlockSize )
const FSConfigPtr &cfg)
: BlockFileIO( cfg->config->blockSize, cfg )
, base( _base )
, cipher( _cipher )
, key( _key )
, haveHeader( uniqueIV )
, haveHeader( cfg->config->uniqueIV )
, externalIV( 0 )
, fileIV( 0 )
, lastFlags( 0 )
, reverseEncryption( _reverseEncryption )
{
fsConfig = cfg;
cipher = cfg->cipher;
key = cfg->key;

static bool warnOnce = false;

if(!warnOnce)
warnOnce = checkSize( fsBlockSize, cipher->cipherBlockSize() );
warnOnce = checkSize( fsConfig->config->blockSize,
fsConfig->cipher->cipherBlockSize() );
}

CipherFileIO::~CipherFileIO()
Expand Down Expand Up @@ -193,7 +193,8 @@ void CipherFileIO::initHeader( )
req.dataLen = 8;
base->read( req );

cipher->streamDecode( buf, sizeof(buf), externalIV, key );
cipher->streamDecode( buf, sizeof(buf),
externalIV, key );

fileIV = 0;
for(int i=0; i<8; ++i)
Expand Down Expand Up @@ -277,13 +278,11 @@ ssize_t CipherFileIO::readOneBlock( const IORequest &req ) const
off_t blockNum = req.offset / bs;

ssize_t readSize = 0;
IORequest tmpReq = req;

if(haveHeader)
{
IORequest tmpReq = req;
tmpReq.offset += HEADER_SIZE;
readSize = base->read( tmpReq );
} else
readSize = base->read( req );
readSize = base->read( tmpReq );

bool ok;
if(readSize > 0)
Expand All @@ -293,10 +292,10 @@ ssize_t CipherFileIO::readOneBlock( const IORequest &req ) const

if(readSize != bs)
{
ok = streamRead( req.data, (int)readSize, blockNum ^ fileIV);
ok = streamRead( tmpReq.data, (int)readSize, blockNum ^ fileIV);
} else
{
ok = blockRead( req.data, (int)readSize, blockNum ^ fileIV);
ok = blockRead( tmpReq.data, (int)readSize, blockNum ^ fileIV);
}

if(!ok)
Expand Down Expand Up @@ -352,7 +351,7 @@ bool CipherFileIO::writeOneBlock( const IORequest &req )
bool CipherFileIO::blockWrite( unsigned char *buf, int size,
uint64_t _iv64 ) const
{
if (!reverseEncryption)
if (!fsConfig->reverseEncryption)
return cipher->blockEncode( buf, size, _iv64, key );
else
return cipher->blockDecode( buf, size, _iv64, key );
Expand All @@ -361,7 +360,7 @@ bool CipherFileIO::blockWrite( unsigned char *buf, int size,
bool CipherFileIO::streamWrite( unsigned char *buf, int size,
uint64_t _iv64 ) const
{
if (!reverseEncryption)
if (!fsConfig->reverseEncryption)
return cipher->streamEncode( buf, size, _iv64, key );
else
return cipher->streamDecode( buf, size, _iv64, key );
Expand All @@ -371,7 +370,7 @@ bool CipherFileIO::streamWrite( unsigned char *buf, int size,
bool CipherFileIO::blockRead( unsigned char *buf, int size,
uint64_t _iv64 ) const
{
if (reverseEncryption)
if (fsConfig->reverseEncryption)
return cipher->blockEncode( buf, size, _iv64, key );
else
{
Expand All @@ -391,7 +390,7 @@ bool CipherFileIO::blockRead( unsigned char *buf, int size,
bool CipherFileIO::streamRead( unsigned char *buf, int size,
uint64_t _iv64 ) const
{
if (reverseEncryption)
if (fsConfig->reverseEncryption)
return cipher->streamEncode( buf, size, _iv64, key );
else
return cipher->streamDecode( buf, size, _iv64, key );
Expand Down
14 changes: 8 additions & 6 deletions encfs/CipherFileIO.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

#include "BlockFileIO.h"
#include "CipherKey.h"
#include "FileUtils.h"

#include <inttypes.h>

Expand All @@ -34,9 +35,7 @@ class CipherFileIO : public BlockFileIO
{
public:
CipherFileIO( const boost::shared_ptr<FileIO> &base,
const boost::shared_ptr<Cipher> &cipher,
const CipherKey &key, int blockSize,
bool uniqueIV, bool reverseEncryption );
const FSConfigPtr &cfg);
virtual ~CipherFileIO();

virtual rel::Interface interface() const;
Expand Down Expand Up @@ -70,16 +69,19 @@ class CipherFileIO : public BlockFileIO
uint64_t iv64 ) const;

boost::shared_ptr<FileIO> base;
boost::shared_ptr<Cipher> cipher;
CipherKey key;

FSConfigPtr fsConfig;

// if haveHeader is true, then we have a transparent file header which
// contains a 64 bit initialization vector.
bool haveHeader;
bool externalIVChaining;
uint64_t externalIV;
uint64_t fileIV;
int lastFlags;
bool reverseEncryption;

boost::shared_ptr<Cipher> cipher;
CipherKey key;
};

#endif
1 change: 1 addition & 0 deletions encfs/Context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "Context.h"
#include "Mutex.h"
#include "FileUtils.h"
#include "DirNode.h"

#include <rlog/rlog.h>

Expand Down
2 changes: 2 additions & 0 deletions encfs/Context.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
using boost::shared_ptr;
struct EncFS_Args;
struct EncFS_Opts;
class FileNode;
class DirNode;

class EncFS_Context
{
Expand Down
36 changes: 10 additions & 26 deletions encfs/DirNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -302,22 +302,23 @@ void RenameOp::undo()
}

DirNode::DirNode(EncFS_Context *_ctx,
const string &sourceDir, const shared_ptr<Config> &_config)
const string &sourceDir,
const FSConfigPtr &_config)
{
pthread_mutex_init( &mutex, 0 );

Lock _lock( mutex );

ctx = _ctx;
rootDir = sourceDir;
config = _config;
fsConfig = _config;

// make sure rootDir ends in '/', so that we can form a path by appending
// the rest..
if( rootDir[ rootDir.length()-1 ] != '/' )
rootDir.append( 1, '/');

naming = config->nameCoding;
naming = fsConfig->nameCoding;
}

DirNode::~DirNode()
Expand Down Expand Up @@ -689,7 +690,7 @@ int DirNode::link( const char *from, const char *to )
rLog(Info, "link %s -> %s", fromCName.c_str(), toCName.c_str());

int res = -EPERM;
if( config->externalIVChaining )
if( fsConfig->config->externalIVChaining )
{
rLog(Info, "hard links not supported with external IV chaining!");
} else
Expand Down Expand Up @@ -745,16 +746,8 @@ shared_ptr<FileNode> DirNode::directLookup( const char *path )
{
return shared_ptr<FileNode>(
new FileNode( this,
config->fsSubVersion,
"unknown", path,
config->cipher, config->key,
config->blockSize, config->blockMACBytes,
config->blockMACRandBytes,
config->uniqueIV,
config->externalIVChaining,
config->forceDecode,
config->reverseEncryption,
config->allowHoles) );
fsConfig,
"unknown", path ));
}

shared_ptr<FileNode> DirNode::findOrCreate( const char *plainName)
Expand All @@ -767,20 +760,11 @@ shared_ptr<FileNode> DirNode::findOrCreate( const char *plainName)
{
uint64_t iv = 0;
string cipherName = naming->encodePath( plainName, &iv );
node.reset( new FileNode( this,
config->fsSubVersion,
node.reset( new FileNode( this, fsConfig,
plainName,
(rootDir + cipherName).c_str(),
config->cipher, config->key,
config->blockSize, config->blockMACBytes,
config->blockMACRandBytes,
config->uniqueIV,
config->externalIVChaining,
config->forceDecode,
config->reverseEncryption,
config->allowHoles) );
(rootDir + cipherName).c_str()));

if(config->externalIVChaining)
if(fsConfig->config->externalIVChaining)
node->setName(0, 0, iv);

rLog(Info, "created FileNode for %s", node->cipherName());
Expand Down
38 changes: 5 additions & 33 deletions encfs/DirNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include "FileNode.h"
#include "NameIO.h"
#include "CipherKey.h"
#include "FSConfig.h"

using boost::shared_ptr;

Expand Down Expand Up @@ -87,38 +88,10 @@ namespace __gnu_cxx
class DirNode
{
public:
struct Config
{
shared_ptr<Cipher> cipher; // cipher to use
CipherKey key; // cipher key to use
shared_ptr<NameIO> nameCoding; // filename encoding implementation
int fsSubVersion; // filesystem version number at creation
int blockSize; // file data block size
bool inactivityTimer; // enables inactivity tracking
int blockMACBytes; // >0 enables per-file-block MAC headers
int blockMACRandBytes; // random bytes in MAC headers
bool uniqueIV; // enable per-file initialization vectors
bool externalIVChaining;
bool forceDecode; // force decoding, even if errors are detected
bool reverseEncryption;
bool allowHoles; // allow holes in files
Config()
: fsSubVersion(0)
, blockSize(1)
, inactivityTimer( false )
, blockMACBytes( 0 )
, blockMACRandBytes( 0 )
, uniqueIV( false )
, externalIVChaining( false )
, forceDecode( false )
, reverseEncryption ( false )
, allowHoles( false )
{ }
};

// sourceDir points to where raw files are stored
DirNode( EncFS_Context *ctx,
const std::string &sourceDir, const shared_ptr<Config> &config );
DirNode(EncFS_Context *ctx,
const std::string &sourceDir,
const FSConfigPtr &config );
~DirNode();

// return the path to the root directory
Expand Down Expand Up @@ -207,9 +180,8 @@ class DirNode

// passed in as configuration
std::string rootDir;
shared_ptr<Config> config;
FSConfigPtr fsConfig;

// stored here to reduce access through config var..
shared_ptr<NameIO> naming;
};

Expand Down
Loading

0 comments on commit 1707123

Please sign in to comment.