File Annotation
Not logged in
e37451d9c2 2007-08-01       drh: /*
e37451d9c2 2007-08-01       drh: ** Copyright (c) 2007 D. Richard Hipp
e37451d9c2 2007-08-01       drh: **
e37451d9c2 2007-08-01       drh: ** This program is free software; you can redistribute it and/or
e37451d9c2 2007-08-01       drh: ** modify it under the terms of the GNU General Public
e37451d9c2 2007-08-01       drh: ** License version 2 as published by the Free Software Foundation.
e37451d9c2 2007-08-01       drh: **
e37451d9c2 2007-08-01       drh: ** This program is distributed in the hope that it will be useful,
e37451d9c2 2007-08-01       drh: ** but WITHOUT ANY WARRANTY; without even the implied warranty of
e37451d9c2 2007-08-01       drh: ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
e37451d9c2 2007-08-01       drh: ** General Public License for more details.
e37451d9c2 2007-08-01       drh: **
e37451d9c2 2007-08-01       drh: ** You should have received a copy of the GNU General Public
e37451d9c2 2007-08-01       drh: ** License along with this library; if not, write to the
e37451d9c2 2007-08-01       drh: ** Free Software Foundation, Inc., 59 Temple Place - Suite 330,
e37451d9c2 2007-08-01       drh: ** Boston, MA  02111-1307, USA.
e37451d9c2 2007-08-01       drh: **
e37451d9c2 2007-08-01       drh: ** Author contact information:
e37451d9c2 2007-08-01       drh: **   drh@hwaci.com
e37451d9c2 2007-08-01       drh: **   http://www.hwaci.com/drh/
e37451d9c2 2007-08-01       drh: **
e37451d9c2 2007-08-01       drh: *******************************************************************************
e37451d9c2 2007-08-01       drh: **
e37451d9c2 2007-08-01       drh: ** This file contains code used to clear-sign documents using an
e37451d9c2 2007-08-01       drh: ** external gpg command.
e37451d9c2 2007-08-01       drh: */
e37451d9c2 2007-08-01       drh: #include "config.h"
e37451d9c2 2007-08-01       drh: #include "clearsign.h"
e37451d9c2 2007-08-01       drh: #include <assert.h>
e37451d9c2 2007-08-01       drh: 
e37451d9c2 2007-08-01       drh: /*
e37451d9c2 2007-08-01       drh: ** Clearsign the given blob.  Put the signed version in
e37451d9c2 2007-08-01       drh: ** pOut.
e37451d9c2 2007-08-01       drh: */
e37451d9c2 2007-08-01       drh: int clearsign(Blob *pIn, Blob *pOut){
e37451d9c2 2007-08-01       drh:   char *zRand;
e37451d9c2 2007-08-01       drh:   char *zIn;
e37451d9c2 2007-08-01       drh:   char *zOut;
5cc845cfeb 2008-02-08       drh:   char *zBase = db_get("pgp-command", "gpg --clearsign -o ");
e37451d9c2 2007-08-01       drh:   char *zCmd;
e37451d9c2 2007-08-01       drh:   int rc;
86cee3d082 2008-11-17       drh:   if( is_false(zBase) ){
86cee3d082 2008-11-17       drh:     return 0;
86cee3d082 2008-11-17       drh:   }
e37451d9c2 2007-08-01       drh:   zRand = db_text(0, "SELECT hex(randomblob(10))");
e37451d9c2 2007-08-01       drh:   zOut = mprintf("out-%s", zRand);
e37451d9c2 2007-08-01       drh:   zIn = mprintf("in-%z", zRand);
e37451d9c2 2007-08-01       drh:   blob_write_to_file(pIn, zOut);
e37451d9c2 2007-08-01       drh:   zCmd = mprintf("%s %s %s", zBase, zIn, zOut);
0eb08b860c 2009-09-16       drh:   rc = portable_system(zCmd);
e37451d9c2 2007-08-01       drh:   free(zCmd);
e37451d9c2 2007-08-01       drh:   if( rc==0 ){
e37451d9c2 2007-08-01       drh:     if( pOut==pIn ){
e37451d9c2 2007-08-01       drh:       blob_reset(pIn);
e37451d9c2 2007-08-01       drh:     }
e37451d9c2 2007-08-01       drh:     blob_zero(pOut);
e37451d9c2 2007-08-01       drh:     blob_read_from_file(pOut, zIn);
e37451d9c2 2007-08-01       drh:   }else{
e37451d9c2 2007-08-01       drh:     if( pOut!=pIn ){
e37451d9c2 2007-08-01       drh:       blob_copy(pOut, pIn);
e37451d9c2 2007-08-01       drh:     }
e37451d9c2 2007-08-01       drh:   }
e37451d9c2 2007-08-01       drh:   unlink(zOut);
e37451d9c2 2007-08-01       drh:   unlink(zIn);
e37451d9c2 2007-08-01       drh:   free(zOut);
e37451d9c2 2007-08-01       drh:   free(zIn);
e37451d9c2 2007-08-01       drh:   return rc;
e37451d9c2 2007-08-01       drh: }