Add iOS-specific fips_algvs application.

Reviewed-by: Dr. Stephen Henson <steve@openssl.org>
This commit is contained in:
Andy Polyakov 2015-05-11 11:39:04 +02:00
parent c6d109051d
commit 2bd3976ed0
7 changed files with 1252 additions and 0 deletions

76
iOS/Makefile Normal file
View file

@ -0,0 +1,76 @@
#
# OpenSSL/iOS/Makefile
#
DIR= iOS
TOP= ..
CC= cc
INCLUDES= -I$(TOP) -I$(TOP)/include
CFLAG= -g -static
MAKEFILE= Makefile
PERL= perl
RM= rm -f
EXE=incore_macho
CFLAGS= $(INCLUDES) $(CFLAG)
top:
@$(MAKE) -f $(TOP)/Makefile reflect THIS=exe
exe: fips_algvs.app/fips_algvs
incore_macho: incore_macho.c $(TOP)/crypto/sha/sha1dgst.c
$(HOSTCC) $(HOSTCFLAGS) -I$(TOP)/include -I$(TOP)/crypto -o $@ incore_macho.c $(TOP)/crypto/sha/sha1dgst.c
fips_algvs.app/fips_algvs: $(TOP)/test/fips_algvs.c $(TOP)/fips/fipscanister.o fopen.m incore_macho
FIPS_SIG=./incore_macho \
$(TOP)/fips/fipsld $(CFLAGS) -I$(TOP)/fips -o $@ \
$(TOP)/test/fips_algvs.c $(TOP)/fips/fipscanister.o \
fopen.m -framework Foundation || rm $@
codesign -f -s "iPhone Developer" --entitlements fips_algvs.app/Entitlements.plist fips_algvs.app || rm $@
install:
@[ -n "$(INSTALLTOP)" ] # should be set by top Makefile...
@set -e; for i in $(EXE); \
do \
(echo installing $$i; \
cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/bin/$$i.new; \
chmod 755 $(INSTALL_PREFIX)$(INSTALLTOP)/bin/$$i.new; \
mv -f $(INSTALL_PREFIX)$(INSTALLTOP)/bin/$$i.new $(INSTALL_PREFIX)$(INSTALLTOP)/bin/$$i ); \
done;
@set -e; for i in $(SCRIPTS); \
do \
(echo installing $$i; \
cp $$i $(INSTALL_PREFIX)$(OPENSSLDIR)/misc/$$i.new; \
chmod 755 $(INSTALL_PREFIX)$(OPENSSLDIR)/misc/$$i.new; \
mv -f $(INSTALL_PREFIX)$(OPENSSLDIR)/misc/$$i.new $(INSTALL_PREFIX)$(OPENSSLDIR)/misc/$$i ); \
done
tags:
ctags $(SRC)
tests:
links:
lint:
lint -DLINT $(INCLUDES) $(SRC)>fluff
depend:
@if [ -z "$(THIS)" ]; then \
$(MAKE) -f $(TOP)/Makefile reflect THIS=$@; \
else \
$(MAKEDEPEND) -- $(CFLAG) $(INCLUDES) $(DEPFLAG) -- $(PROGS) $(SRC); \
fi
dclean:
$(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new
mv -f Makefile.new $(MAKEFILE)
clean:
rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff $(EXE)
rm -f fips_algvs.app/fips_algvs
# DO NOT DELETE THIS LINE -- make depend depends on it.

View file

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>get-task-allow</key>
<true/>
</dict>
</plist>

View file

@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleName</key>
<string>fips_algvs</string>
<key>CFBundleSupportedPlatforms</key>
<array>
<string>iPhoneOS</string>
</array>
<key>CFBundleExecutable</key>
<string>fips_algvs</string>
<key>CFBundleIdentifier</key>
<string>fips_algvs</string>
<key>CFBundleResourceSpecification</key>
<string>ResourceRules.plist</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>CFBundleDisplayName</key>
<string>fips_algvs</string>
<key>CFBundleVersion</key>
<string>1.0</string>
</dict>
</plist>

View file

@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>rules</key>
<dict>
<key>.*</key>
<true/>
<key>Info.plist</key>
<dict>
<key>omit</key>
<true/>
<key>weight</key>
<real>10</real>
</dict>
<key>ResourceRules.plist</key>
<dict>
<key>omit</key>
<true/>
<key>weight</key>
<real>100</real>
</dict>
</dict>
</dict>
</plist>

93
iOS/fopen.m Normal file
View file

@ -0,0 +1,93 @@
#include <stdio.h>
#include <dlfcn.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <Foundation/Foundation.h>
static FILE *(*libc_fopen)(const char *, const char *) = NULL;
__attribute__((constructor))
static void pre_main(void)
{
/*
* Pull reference to fopen(3) from libc.
*/
void *handle = dlopen("libSystem.B.dylib",RTLD_LAZY);
if (handle) {
libc_fopen = dlsym(handle,"fopen");
dlclose(handle);
}
/*
* Change to Documents directory.
*/
NSString *docs = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
NSFileManager *filemgr = [NSFileManager defaultManager];
[filemgr changeCurrentDirectoryPath: docs];
[filemgr release];
}
char *mkdirhier(char *path)
{
char *slash;
struct stat buf;
if (path[0]=='.' && path[1]=='/') path+=2;
if ((slash = strrchr(path,'/'))) {
*slash = '\0';
if (stat(path,&buf)==0) {
*slash = '/';
return NULL;
}
(void)mkdirhier(path);
mkdir (path,0777);
*slash = '/';
}
return slash;
}
/*
* Replacement fopen(3)
*/
FILE *fopen(const char *filename, const char *mode)
{
FILE *ret;
if ((ret = (*libc_fopen)(filename,mode)) == NULL) {
/*
* If file is not present in Documents directory, try from Bundle.
*/
NSString *nsspath = [NSString stringWithFormat:@"%@/%s",
[[NSBundle mainBundle] bundlePath],
filename];
if ((ret = (*libc_fopen)([nsspath cStringUsingEncoding:NSUTF8StringEncoding],mode)) == NULL &&
mode[0]=='w' &&
((filename[0]!='.' && filename[0]!='/') ||
(filename[0]=='.' && filename[1]=='/')) ) {
/*
* If not present in Bundle, create directory in Documents
*/
char *path = strdup(filename), *slash;
static int once = 1;
if ((slash = mkdirhier(path)) && once) {
/*
* For some reason iOS truncates first created file
* upon program exit, so we create one preemptively...
*/
once = 0;
strcpy(slash,"/.0");
creat(path,0444);
}
free(path);
ret = (*libc_fopen)(filename,mode);
}
}
return ret;
}

1016
iOS/incore_macho.c Normal file

File diff suppressed because it is too large Load diff

View file

@ -265,6 +265,16 @@ int main(int argc, char **argv)
SysInit();
#endif
#if defined(__APPLE__) && (defined(__arm__) || defined(__aarch64__))
if (*args && !strcmp(*args, "-noaccel"))
{
extern unsigned int OPENSSL_armcap_P;
OPENSSL_armcap_P=0;
args++;
argc--;
}
#endif
if (*args && *args[0] != '-')
{
rv = run_prg(argc - 1, args);