Quantcast
Channel: Make you feel cozy
Viewing all 46 articles
Browse latest View live

diskpart 사용법


인크립션 - 실용주의 암호학 정리

$
0
0

Permutation(순서 바꿈) : 문자 순서를 바꿈

Substitution(문자 바꿈) :  문자를 다른 문자로 바꿈

SPN(Substitution-Permutation Network) : 문자 바꾸고 순서 섞으면 SPN 1 round


<암호화 평가기준>

- 키 정보가 커야함(매칭 시도 횟수가 늘어남)

- 혼돈 : 암호화된 결과물에서 키 정보를 얻기가 얼마나 어려운가

- 확산 : 암호화된 결과물에서 원본 정보를 얻기가 얼마나 어려운가 (암호문과 원본과의 관계를 알수 없어야 함)


단위 암호 시스템 = 알고리즘 * 운영모드

- 알고리즘 : SPN 설계에 의해 반복

- 운영모드 

기밀성 : ECB, CBC, CFB, OFB, CTR, XTS_AES

무결성 : CMAC

기밀성 + 무결성 : CCM, GCM


CBC,CFB,OFB : IV 필요


암호시스템 공격

- COA(Ciphertext Only Attack) : 공격자가 암호문만 알때

- KPA(Known Plaintext Attack) : 공격자가 원문 일부와 그 일부 암호문을 알때

- CPA(Chosen Plaintext Attack) : 공격자가 원문의 일부를 마음대로 선택해서 그에 해당하는 암호문을 확인할수 있을때


암호 안정성

- Hash 함수는 암호화의 2배 키 길이 권고 설정(키설정)


OPE : Order Preserving Encryption(순서유지암호화)

- CPA 공격 가능


데이터베이스 암호화

- API : 어플리케이션 수정

- 플러그인 : DBMS에 특정 모듈 탑재

- 하이브리드

- TDE(Transparent Data Encryption) 방식 : DB에서 제공하는 암호화 모듈 사용


데이터베이스 암호화의 키 변경

- 기간별로 테이블을 나누면 키 변경으로 인한 이슈 최소화 가능


FPE(형태보존암호화) : Format Preserving Encryption

- 신용카드 암호화 등에 이용


공인인증서 비판(보안기술, 기술의 구현방법, 규제)

- 안정성 : 하드에 저장됨 (개인키 관리가 잘 안됨) => USIM 등 이용이 적합

- 편리성 : ActiveX만 지원(플랫폼 종속적) =>다양한 플랫폼 지원 노력

- 부인방지 : 사용자에게 책임 전가(의무화) => 의무화 해제 및 부인방지의 효력 재고려 필요


저작자 표시비영리변경 금지
Creative Commons License
Creative Commons License

마그네틱 카드 구성 정보

HMAC 구성 방법

$
0
0

HMAC 구성방법



 

사진 출처: https://en.wikipedia.org/wiki/Hash-based_message_authentication_code

 

1. key에 대한 패딩: hash함수의 block 길이 만큼 0으로 padding

2. 패딩한 key와 ipad의 XOR 함 (ipad는 00110110(0x36) 의 hash함수의 block 길이 만큼 반복 된 값)

3. 메세지와 XOR한 값을 결합

4. sha1 (1st pass) hash값 계산

5. 패딩한 key와 opad의 XOR 함 (opad는 01011100(0x5c) 의 hash함수의 block길이 만큼 반복 된 값)

6. 5에서 수행한 값을 hash sum1과의 결함  

7. sha1 (2nd pass) hash값 계산

8. MAC값 생성

[출처] HMAC이란?|작성자 Sehi


저작자 표시비영리변경 금지
Creative Commons License
Creative Commons License

우분투 16.04 LTS 64bit에서 안드로이드 4.4 커널 컴파일 관련 트러블슈팅

$
0
0

1. 관련 패키지 설치

sudo apt-get install git-core gnupg flex bison gperf build-essential \

  zip curl zlib1g-dev gcc-multilib g++-multilib libc6-dev-i386 \

  lib32ncurses5-dev x11proto-core-dev libx11-dev lib32z-dev ccache \

  libgl1-mesa-dev libxml2-utils xsltproc unzip


2. make 4.1 관련 스크립트 추가

 vi ./build/core/main.mk 에서 4.1 관련 스크립트 추가 


 42 ifeq (,$(findstring CYGWIN,$(shell uname -sm)))

 43 ifeq (0,$(shell expr $$(echo $(MAKE_VERSION) | sed "s/[^0-9\.].*//") = 3.81))

 44 ifeq (0,$(shell expr $$(echo $(MAKE_VERSION) | sed "s/[^0-9\.].*//") = 3.82))

 45 ifeq (0,$(shell expr $$(echo $(MAKE_VERSION) | sed "s/[^0-9\.].*//") = 4.1))

 46 $(warning ********************************************************************************)

 47 $(warning *  You are using version $(MAKE_VERSION) of make.)

 48 $(warning *  Android can only be built by versions 3.81 and 3.82.)

 49 $(warning *  see https://source.android.com/source/download.html)

 50 $(warning ********************************************************************************)

 51 $(error stopping)

 52 endif

 53 endif

 54 endif

 55 endif


3. 자바 패키지 변경 설치 (jdk 1.6 필요)

sudo add-apt-repository ppa:webupd8team/java

sudo apt-get update

sudo apt-get install oracle-java6-installer


4. 드라이버 소스 다운로드

https://developers.google.com/android/drivers#hammerheadktu84p

3개의 sh 파일 압축 해제 후 소스 디렉토리에서 실행

extract-qcom-hammerhead.sh

extract-broadcom-hammerhead.sh

extract-lge-hammerhead.sh


저작자 표시비영리변경 금지
Creative Commons License
Creative Commons License

IMEI, IMSI, UDID

$
0
0

IMEI(International Mobile Equipment Identity) : 단말기 고유 번호

<구조>

AA-BBBBBB-CCCCCCD or EE
Old IMEITACFACSerial number(Optional) Luhn checksum
New IMEITAC
Old IMEISVTACFACSoftware Version Number (SVN).
New IMEISVTAC


IMSI(International mobile subscriber identity) : 범용개인식별모듈(USIM) 카드의 고유번호

IMSI:410072821393853
MCC410Pakistan
MNC07Warid Pakistan
MSIN2821393853
IMSI:310150123456789
MCC310USA
MNC150AT&T Mobility
MSIN123456789


UDID(Unique Device Identifier Description) : 아이폰 전용 단말 고유번호

UDID = SHA1(serial + IMEI + wifiMac + bluetoothMac)



<관련 안드로이드 소스>

TelephonyManager mTelephonyMgr = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); 
String imsi = mTelephonyMgr.getSubscriberId(); 
String imei = mTelephonyMgr.getDeviceId(); 
String phoneNumber = mTelephonyMgr.getLine1Number();


저작자 표시비영리변경 금지
Creative Commons License
Creative Commons License

IOS 취약점 점검시 파일 변화 비교

$
0
0

<파일 비교>

cd app_old

find . -type f -exec md5sum {} \;   | sed "s/*\.\//\.\//" > ../app_old.md5

cd ../app_new

find . -type f -exec md5sum {} \;   | sed "s/*\.\//\.\//" > ../app_new.md5

cd ../bundle_old

find . -type f -exec md5sum {} \;   | sed "s/*\.\//\.\//" > ../bundle_old.md5

cd ../bundle_new

find . -type f -exec md5sum {} \;   | sed "s/*\.\//\.\//" > ../bundle_new.md5

<신규 또는 변경된 파일만 추출>
mkdir app_newfile
diff app_old.md5 app_new.md5  | grep  "^>" | awk '{print "./app_new/"$3}' | while read line; do cp  $line app_newfile; done;


<문자열 일괄 추출>
find . -type f -exec echo '[FILE] '{} \; -exec strings {} \; > ../app_new_str.txt
find . -type f -exec echo '[FILE] '{} \; -exec strings {} \; > ../bundle_new_str.txt



<파일 상태 비교를 통한 침해여부 판단>
cat DIR.list | while read line; do find  $line -type f; done |sort > new_file_list
cat FILE.list |sort > old_file_list
diff old_file_list new_file_list > diff.txt

<md5 hash 다시 만들기>

cat FILE.list.md5sum  | awk '{print $2}' | while read line ; do md5sum $line; done > cur_md5






저작자 표시비영리변경 금지
Creative Commons License
Creative Commons License

RSA 공개키 비밀키 생성 과정

$
0
0

http://blog.naver.com/at3650/40200115609

<모듈라 설명>

a ≡ b (mod d) => a= kd + b  => a-b = kd => a-b ≡ 0  (mod d)



두 수 a,b,c 가 모두 법 d에(mod d) 대해 합동이라 하면

 

(1) 반사성(Refiexible) :  a ≡ a  

(2) 대칭성(Symmetric) : a ≡ b  이면  b ≡ a

(3) 추이성(Transtive) :  a ≡ b 이고 b ≡ c 이면 a≡c

가 성립한다. (1),(2),(3)이 모두 성립하므로 합동식은 동치관계라고 볼 수 있다.


두 수 a,b,c 가 모두 법 d에(mod d) 대해 합동이라 하면

(1)   a ≡ b ,  a` ≡ b` 이면  a+a`  ≡ b+b`

(2)  a ≡ b ,  a` ≡ b` 이면  a-a`  ≡ b-b`

(3) a ≡ b ,  a` ≡ b` 이면   aa`  ≡ bb`


<예시>

2457 = 2 × 10³ + 4 × 10² + 5 ×10 + 7×1

≡ 2×1 + 4×1 + 5×1 + 7× 1   (mod 9)


2 × 10³ 의 경우

1) 2 ≡ 2  (mod 9) ; (∵ reflexible),  

2) 10³  ≡ 1 (mod 9)

⇒ 2×10³ (mod 9) ≡ 2(mod 9) × 1 (mod 9) = 2 (mod 9) (∵  a ≡ b ,  a` ≡ b` 이면   aa`  ≡ bb`

 

<오일러 파이>

φ(n) - 오일러 파이, 특정 자연수와 서로수인 자연수의 갯수

φ(10) = 4 (1,3,5,7)

φ(p) = p-1 (p가 소수일때)


<오일러 파이 구하기>

기본원리 : 전체에서 소인수들의 배수인 수들을 제외하면 됨

=> 1 - n(AUBUC)


φ(30) 구하기 예시

30의 소인수는 2, 3, 5

A=1, B=1/2, C=1/3, D=1/5 라 하면

P(X) = A³ - AB - AC - AD + BC + BD + CD - BCD

P(X) =  A³ - A²B - A²C - A²D + ABC + ABD + ACD - BCD 

P(X) = A³ - (B+C+D)A² + (BC+CD+BD)A - BCD

P(X) = (A-B)(A-C)(A-D) 

따라서 30이 가진 서로수는 8개


앞에서 살펴본 φ(n)를 정규한 수식으로 표현해보면 아래와 같이 표현할수 있음


1000의 오일러 파이 값 구하기 적용

1000 = 2^3 * 5^3 => 1000(1-1/2)(1-1/5) = 400


<페르마의 소정리>

* 기초 원리

 

* 가정

  (어떤 임의의 두 수를 골라도 법 p와 합동이 되지 않는다)


m의 변수들은 모두 나머지가 다르기 때문에 모두를 곱한 값의 (mod p)를 적용해보면

(p-1)! (mod p)가 된다. 따라서 아래식이 성립한다

(p-1)!중에서 p로 나누어지는 수는 없으므로 아래 식은 성립한다

(p가 정수 a를 나누지 않는 소수인 경우)



<페르마의 일반화된 소정리>

 이고   이므로

 (a와 n이 서로 소인경우)


<유클리드 호제법 원리>

A >= B인 어떤 두 정수 A와 B가 있을 때(A = Bq + r로 나타낼 수 있다.)

A와 B의 최대공약수 gcd(A, B) = d는 gcd(B, r)과 같다.

즉, 쉽게 말하면 두 수의 최대공약수는 "큰 수를 작은 수로 나눈 나머지"와 "작은 수"의 최대공약수와 같다는 것이다.


증명.

gcd(A, B) = d에 의해서 A = ad, B = bd (따라서 a와 b는 서로소이다.)

A = Bq + r 이므로 r = A - Bq = ad - bdq = (a-bq)*d 이다.


여기서 B = bd 와 r = (a-bq)d이므로 d는 B와 r의 공약수 중 하나라는 것을 알 수 있다.

B와 r의 최대공약수를 c라 하면 c >= d 라 할 수 있다.


B = cs, r = ct라 하면 (s, t도 서로소)

A = Bq + r = csq + ct = (sq+t)c 이다.

c는 A와 B의 공약 수 중 하나라는 것을 알 수 있다.

따라서 c는 A와 B의 최대 공약수인 d의 약수이고 d >= c 임을 알 수 있다.


따라서 c >= d 이고 d >= c 이므로 d = c 라는 결론을 얻게 된다.

즉 gcd(A, B) = gcd(B, r)이다.


<유클리드 호제법 예시>

A = Bq + r  => gcd(A, B) = gcd(B, r)

GCD(270,192) = GCD(192,78) = GCD(78,36) = GCD(36,6) = GCD(6,0) = 6


알고리즘

A와 B의 최대공약수 GCD(A,B)를 알아내는 유클리드 호제법은 다음과 같습니다:
  • A=0이면 GCD(0,B)=B이므로 GCD(A,B)=B이고 멈춥니다. 
  • B=0이면 GCD(A,0)=A이므로 GCD(A,B)=A이고 멈춥니다. 
  • A를 A = B⋅Q + R의 형식으로 씁니다
  • GCD(A,B) = GCD(B,R)이므로 유클리드 호제법을 이용하여 GCD(B,R)을 찾습니다.

예제:

270과 192의 최대공약수를 찾아 봅시다
  • A=270, B=192
  • A ≠0
  • B ≠0
  • 긴 나눗셈을 이용하면 270/192=1 나머지 78입니다. 이를 다음과 같이 바꿔 쓸 수 있습니다: 270 = 192 * 1 +78
  • GCD(270,192)=GCD(192,78)이므로 GCD(192,78)를 찾습니다
A=192, B=78
  • A ≠0
  • B ≠0
  • 긴 나눗셈을 이용하면 192/78 = 2 나머지 36입니다. 이를 다음과 같이 바꿔 쓸 수 있습니다:
  • 192 = 78 * 2 + 36
  • GCD(192,78)=GCD(78,36) 이므로 GCD(78,36)을 찾습니다
A=78, B=36
  • A ≠0
  • B ≠0
  • 긴 나눗셈을 이용하면 78/36 = 2 나머지 6입니다. 이를 다음과 같이 바꿔 쓸 수 있습니다:
  • 78 = 36 * 2 + 6
  • GCD(78,36)=GCD(36,6)이므로 GCD(36,6)을 찾습니다
A=36, B=6
  • A ≠0
  • B ≠0
  • 긴 나눗셈을 이용하면 36/6 나머지 0입니다. 이를 다음과 같이 바꿔 쓸 수 있습니다:
  • 36 = 6 * 6 + 0
  • GCD(36,6)=GCD(6,0) 이므로 GCD(6,0)을 찾습니다
A=6, B=0
  • A ≠0
  • B =0, GCD(6,0)=6
이제까지의 과정을 정리하면 다음과 같습니다:
GCD(270,192) = GCD(192,78) = GCD(78,36) = GCD(36,6) = GCD(6,0) = 6
GCD(270,192) = 6


<RSA 공개키 및 비밀키 생성 원리>

온라인으로 검증해보기 : http://rsatools.wforums.net/#encrypt

  • 뽀로로와 패티가 비밀연애를 위해 암호화된 연애편지를 주고 받으려 한다면...
  • 뽀로로는 서로 다른 두 소수 (P, Q)를 선택한다.
  • P와 Q를 곱해 N 을 구한다.  (N=PxQ)
  • 오일러 피 함수에 해당되는 φ(N) = (P-1)(Q-1)을 구한다.
  • φ(N) 보다는 작으면서 φ(N)와 서로소인 정수 e를 찾는다.  (1 < e < φ(N)) 
  • 확장된 유클리드 호제법을 이용해 (d x e)/φ(N) 일 때 나머지가 1인 정수 d 를 구한다. 
  • 처음에 선택한 두 소수 (P, Q) 및 φ(N)는 유출되면 안되므로 삭제한다.
  • 패티도 동일한 과정을 거친다.


<RSA 공개키 및 비밀키 생성 예제>

p=13, q=17 지정

φ(N) = 12 * 16 = 192

공개키는 e 는 5로 지정

비밀키는 아래 식으로 유도

5d = 192k +1

k를 2라고 하면 d는 77이 된다

공개키 (221, 5), 비밀키 (221,77)


<확장된 유클리드 호제법>

GCD(A,B) = c 인경우 => pA+qB = c 식을 구할 수 있음


e가 정해진 경우 d를 구하기 위해 사용

GCD(φ(N),e) => pφ(N)+qe = 1 로 표현가능  ( φ(N), e는 서로소 이므로 c는 1)

pφ(N)+qe = 1 에서 pφ(N)는 φ(N)의 배수 이므로

qe (mod φ(N)) ≡ 1  이어야 한다.

따라서 q값이 우리가 구하는 d값이 된다


<확장된 유클리드 호제법 예시>

p=13, q=17, φ(N)=192, e=5 인경우 d를 구하면

GCD(192,5) => 192 = 5 * 38 +2   => 2 = 192 - 5*38

= GCD(5,2) => 5 = 2 * 2 + 1       

이를 φ(N)=192, e=5 각각 배수의 합 형태로 만들어야 하므로

1 = 5 - 2 * 2

1 = 5 - 2 * (192 - 5*38) = 5 * 77 - 2 * 192

따라서 d는 77이 된다


<암복호화 원리>

c = me mod n

m = cd mod n


cd mod n  med mod n 

 


1) m,n 이 서로소 인경우

페르마의 정리에 따라


2) m,n이 서로소가 아닌경우

φ(n) = (p-1)(q-1) 

이므로

 이 p,q 각각으로 나누었을때 m이 나머지로 남게 된다. 따라서

에서 m을 뺀값은 p,q로 모두 나누어 지며 이는 p*q = n 으로 나누어진다.

따라서 아래와 같이 m 값을 추출되게 된다.


<암복호화 과정 예시>

공개키 (221, 5), 비밀키 (221,77)

* 암호화

c = me mod n

* J(10진수 74)를 암호화 해보자

74^5 mod 221= 211 


* 복호화

공개키 (221, 5), 비밀키 (221,77)

m = cd mod n

211^77 mod 221 = 74


저작자 표시비영리변경 금지
Creative Commons License
Creative Commons License

RSA Key 파일 구조

$
0
0

RSA Key 파일은 DER, PEM 2개 구조가 있음

Distinguished Encoding Rules (DER)을 Base64 encoding한 정보가 PEM으로 인지하면 됨


<PKCS#1 공개키 구조>

-----BEGIN RSA PUBLIC KEY-----
RSAPublicKey ::= SEQUENCE {
    modulus           INTEGER,  -- n
    publicExponent    INTEGER   -- e
}
-----END RSA PUBLIC KEY-----

<PKCS#1 개인키 구조>

-----BEGIN RSA PRIVATE KEY-----
RSAPrivateKey ::= SEQUENCE {
  version           Version,
  modulus           INTEGER,  -- n
  publicExponent    INTEGER,  -- e
  privateExponent   INTEGER,  -- d
  prime1            INTEGER,  -- p
  prime2            INTEGER,  -- q
  exponent1         INTEGER,  -- d mod (p-1)
  exponent2         INTEGER,  -- d mod (q-1)
  coefficient       INTEGER,  -- (inverse of q) mod p
  otherPrimeInfos   OtherPrimeInfos OPTIONAL
}
-----END RSA PRIVATE KEY-----


<PKCS#8 공개키 구조>

-----BEGIN PUBLIC KEY-----
PublicKeyInfo ::= SEQUENCE {
  algorithm       AlgorithmIdentifier,
  PublicKey       BIT STRING
}

AlgorithmIdentifier ::= SEQUENCE {
  algorithm       OBJECT IDENTIFIER,
  parameters      ANY DEFINED BY algorithm OPTIONAL
}
-----END PUBLIC KEY-----

<PKCS#8 개인키 구조>

-----BEGIN PRIVATE KEY-----
PrivateKeyInfo ::= SEQUENCE {
  version         Version,
  algorithm       AlgorithmIdentifier,
  PrivateKey      BIT STRING
}

AlgorithmIdentifier ::= SEQUENCE {
  algorithm       OBJECT IDENTIFIER,
  parameters      ANY DEFINED BY algorithm OPTIONAL
}
-----END PRIVATE KEY-----


저작자 표시비영리변경 금지
Creative Commons License
Creative Commons License

std:random_device의 난수 안전성

$
0
0

TL;DR: only use std::random_device to generate seeds for the defined PRNG's within this library. Otherwise use a cryptographic library such as Crypto++, Bothan, OpenSSL etc. to generate secure random numbers.

To have an idea why std::random_device is required it is important to see it in the light of the context for which it was defined.

std::random_device is part of a set of classes and methods that are used to generate deterministic/pseudo random number sequences fast. One example - also shown in the slides - is the Mersenne twister algorithm, which is certainly not cryptographically secure (which is actually).

Now this is all very nice, but as the defined algorithms are all deterministic, this is arguably not what the users may be after: they want a fast random number generator that doesn't produce the same stream all of the time. Some kind of entropy source is required to seed the insecure PRNG. This is where std::random_device comes into action, it is used to seed the Mersenne twister (as shown in the slides referred to in the answer).

This entropy source provided by std::random_device may be slow as long as it provides non-deterministic random numbers. If it is cryptographically secure then this won't be seen as a drawback. The seed in the end doesn't have a security requirement - it will be used to seed a non-secure PRNG after all. As long as it is better than taking the time in milliseconds it's probably fine.

The slides show a speed difference of about 250 times for the Mersenne twister and the slow system provided non-deterministic random number generator. This clearly demonstrates why local, deterministic PRNG's can help to speed up random number generation. Mind that local PRNG's won't slow down when used from multiple threads. The system generator could be speedy when accessed by multiple threads, but this is certainly not a given. Sometimes system RNG's may even block or have latency or related issues.



No, because that's not what std::random_device is designed for; it's designed to generate random numbers, not to be secure.

In the context of security, randomness is something that is useful for key generation, but randomness is not something that is absolutely needed. For example, AES does not use any randomness, yet AES-256 is what is used to encrypt top secret information in the US.

One area where randomness and security cross, is when a random key is generated and used; if I can guess the seed and know the random protocol used, there's a good chance I can then use that same seed value to generate the same "random" value and thus the same key.

std::random_device will use a hardware module (like a hardware TPM) if one is available, otherwise it will use whatever the OS has as a RNG (like CryptGenRandom in Windows, or /dev/random in *nix systems), which might even be a PRNG (pseudo-random number generator), which might generate the same number depending on the random number algorithm used. As a side note: much like how the AES instruction set was incorporated into chipsets to speed up encryption and decryption, hardware RNG's help to give a larger entropy pool and faster random number generation as the algorithms are moved into hardware.

So if you are using std::random_device in any sort of cryptographic key generation, you'll need to be aware what random number generator is being used on the system being deployed to, otherwise you can have collisions and thus your encrypted system can be susceptible to duplicate key types of attack.


https://stackoverflow.com/questions/44867500/is-stdrandom-device-cryptographic-secure

저작자 표시비영리변경 금지
Creative Commons License
Creative Commons License

안드로이드 난독화 솔루션 정보

$
0
0

Proguard 적용 기능

- Shrinking : 사용되지 않는 클래스 혹은 메소드, 필드를 찾아 삭제

- Optimization : 최적화

- Renaming : 식별자 변환


Proguard 미적용 기능

- String encryption : 문자열 암호화

- Class encryption : 클래스 암호화

- API hiding : API 은닉

- Native library encryption : 네이티비 라이브러리 암호화



PKCS 표준

$
0
0

[출처 : http://www.nexpert.net/438]


시작하며

PKCS는 공개키 기반 구조 (PKI)로 Secure UC 를 적용할 때마다 부딪히는 용어입니다. 단일 제조사 시스템간 구현에는 PKCS라는 용어를 몰라도 설정에 문제가 없지만, 이기종 제품이나 외부 CA 서버간 연동에는 필수적으로 나오는 용어입니다. 언제나 용어란 것이 알고나면 쉽지만, 모르면 무슨 얘기인지 모릅니다. 


이번 글에서는 저도 이해하는 데 좀 어려웠던 PKCS에 대해 살펴보겠습니다.


PKCS (Public-Key Cryptography Standard)의 개요 

PKCS는 공개키 기반 구조 (PKI, Public Key Infrastructure)에서 인터넷을 이용해 안전하게 정보를 교환하기 위한 제조사간 비공식 표준 프로토콜로 미국의 RSA가 개발한 암호 작성 시스템입니다. PKCS는 애플, 마이크로소프트, DEC 등의 회사에서 공동 개발하였지만, IETF에서 RFC 로 받아들이면서 공식적인 표준으로 인정하고 있습니다. 


PKCS세부 항목


PKCS에서 다루고 있는 Credential은  정보 시스템에서 암호화된 개인정보로 개인의 공개키 암호 알고리즘을 위한 공개키 및 개인키 쌍, 공개키 인증서, CA 관련 정보, 패스워드 등을 포함하는 암호 정보의 총합입니다. 이를 다루는 PKCS는 #1 에서 #15까지 있으며, 아래 표를 참조하시기 바랍니다. 




PKCS #1 RSA Cryptography Standard Version 1.5 (RFC 2313, 3447 )

RSA 알고리즘을 이용해 데이터를 암호화하고 전자 서명하는 방법에 대한 내용과 RSA 공개 키의 구문을 설명합니다. PKCS #2와 #4는 폐기되고 주요 내용은 PKCS #1에 포함되었습니다. 


PKCS #3 Diffie-Hellman Key Agreement Standard  키 합의 표준 

디피헬먼 키분배 알고리즘의 구현을 위한 방법을 설명하였습니다.PKCS #3는 OSI의 전송 및 네트워크 계층에서의 안전한 전송 채널 구축을 위한 프로토콜에 사용되는 것이 목적입니다.


PKCS #5 Password-based Cryptography Specification Version 2.0  (RFC 2898)

개인 키정보를 사용자의 패스워드에 기반하여 암호화하는 방법을 정의한 패스워드기반 암호표준입니다. PKCS #5는 외부에서 개인키를 생성하여 당사자에게 전송시킬 때 개인키를 암호화하는 것을 목적으로 합니다. 개인키를 특징 기기나 개인이 사용하기 위해 복호화하기 위해서는 패스워드가 필요합니다. 


PKCS #6 Extended-Certificate Syntax Standard 

X.509 인증서의 version 1을 확장했지만, 현재는  X.509 Version 3가 사용되므로 사용되지 않습니다.  


PKCS #7 Cryptographic Message Syntax Version 1.5 (RFC 3369)

전자 서명이나 전자 봉투와 같은 암호 응용에 대한 일반적인 구문 표현이빈다. PKCS #7은 PEM과 호환되니다. 


PKCS #8 Private-Key Information Syntax Specification Version 1.2 (RFC 5208) 

개인키 정보 구문 표준으로 개인키와 속성 정보를 포함한 암호화된 개인키를 위한 구문을 정의합니다.


PKCS #9 Selected Object Classes and Attribute Types

선택된 속성 형식 표준으로 PKCS #6 확장 인증서 구문 표준의 확장 인증서, PKCS #7의 전자서명 메세지와 PKCS #8 개인키 정보에서 사용되는 속성 유형들을 정의합니다.


PKCS #10 Certification Request Syntax Specification v1.7 (RFC 2986)

인증 요청 구문 표준으로 인증서 발급 요청서를 위한 구문 정의합니다. 인증서 발급 요청서는 사용자 식별 명칭, 공개키, 옵션인 속성들로 구성되어 사용자가 인증서  발생을 요구하기 위하여 인증 기관에 요청하는 구문입니다. 


PKCS #11 Cryptographic Token Interface Standard 암호 토큰 인터페이스 표준

스마트카드와 같은 암호화 장비를 위한 기술 독립 프로그래밍 인터페이스 (CAPI) 를 설명합니다.  


PKCS #12   Personal Information Exchange Syntax Standard 개인 정보 교환 표준

사용자의 개인키, 인증 등의 저장과 교환을 위한 포맷을 설명합니다. 


PKCS #13 ECC 타원 곡선 암호 표준

타원 곡선 암호에 기반한 공개 키를 암호화를 하고 서명하는 매커니즘을 설명합니다. 


PKCS #14  의사 난수 생성 표준 

블록 암호, 해시 함수 등 다양한 방법의 의사 난수 생성 설명합니다.


PKCS #15   암호 토큰 정보 형식 표준

암호화 토큰에 저장된 암호화 보증서의 포맷을 위한 표준을 설명합니다. 



인증서 발행 방식의 차이 : PKCS #10 과 PKCS #5

우리가 일반적으로 사용하는 것은 PKCS #5와 PKCS #10입니다. 이 두 가지는 개인키와 공개키를 생성하는 방식에서 차이가 있습니다. PKCS #10은 단말이나 사용자가 직접 키를 생성한 후에 공개키를 CA 서버로 부터 인증받아 인증서를 서명받은 후에 배포합니다. 개인키가 기기나 사용자를 벗어나지 않음으로 안정성을 보장받는 방법입니다. PKCS #5는 외부 CA 서버로 부터 단말이나 사용자의 개인키와 공인키를 생성한 후에 패스워드로 안전하게 암호화하여 기기나 사용자에게 주입하는 방식입니다. 따라서, PKCS #5 방식을 지원하면 보통 PKCS #10을 지원하지 않고, 그 역도 마찬가지 입니다. 



인터넷 전화 보안의 관점에서 어떤 방식이 더 안전한가라는 물음이 생깁니다. 웹서핑도 해보고 자료도 찾아보았지만, 이 두가지에 대한 비교 자료가 없으므로 쉽게 단언할 수는 없습니다. 일반적인 환경에서 두 가지가 혼용되어 사용되고 기업의 상황에 따라 적절하게 사용하면 될 듯합니다. 


현재 인터넷 전화 보안을 위해 두 가지 방식이 혼용되고 있습니다. 국산 장비들은 PKCS #5를, 외산 장비들은 PKCS #10을 지원합니다. 시스코 UC 구현을 위한 CUCM, IP Phone, CUBE 등은 모두 PKCS #10을 지원합니다. 


출처: http://www.nexpert.net/438 [NExpert]

안드로이드 주요 함수 정리

$
0
0

Intent 데이터 추출

- Uri uri = Intent.getData()

- Bundle bundle = Intent.getExtras()


Intent 데이터 전송

- startActivity(indent)

- startActivityForResult(indent, REQUEST_CODE)


Broadcast 데이터 전송

- sendBroadcast(intent)

- sendOrderedBroadcast(intent)


Thread 데이터 추출

- Message msg = handler.obtainMessage()

  Bundle = msg.getData()


Thread 데이터 전송

- handler.sendMessage(msg)


스마트 컨트렉트 사고 사례

$
0
0

1. The DAO 사건

https://www.cryptocompare.com/coins/guides/the-dao-the-hack-the-soft-fork-and-the-hard-fork/


2. Parity 지갑 사건

https://medium.freecodecamp.org/a-hacker-stole-31m-of-ether-how-it-happened-and-what-it-means-for-ethereum-9e5dc29e33ce

git VS svn 명령어 비교

$
0
0


조작GitSubversion
저장소의 복제git clonesvn checkout
커밋git commitsvn commit
커밋의 상세내용을 확인하고 싶다git showsvn cat
상태 확인git statussvn status
변경 내용 확인git diffsvn diff
로그 확인git logsvn log
추가git addsvn add
이동git mvsvn mv
삭제git rmsvn rm
변경 취소git checkout / git resetsvn revert
브랜치 작성git branchsvn copy
브랜치의 전환git checkoutsvn switch
병합git mergesvn merge
태그 작성git tagsvn copy
변경 사항 업데이트git pull / git fetchsvn update
원격 저장소에 반영git pushsvn commit
무시할 파일 목록.gitignore.svnignore

<Tip - 소스 원래대로 복구> 

git reset --hard origin/master


Keystore SoftKeymaster USER_PKEY 포맷 분석

$
0
0

<초기 헤더 정보>

- [0-3] : 메타정보(version, type, flags, info)

- [4-19] : AES 복호화를 위한 IV값 (128bit)

- [20-35] : MD5 Hash 값

- [36-39] : Blob의 길이(Integer 타입)

- [40~  ] : Key blob (SoftwareKeyblob, Qcom blob 등등)

------------------------------------------------------------------------------

<SoftwareKeyblob 구조>

[00-03] MAGIC NUM : PK#8

[04-07] KEY TYPE : EVP_PKEY_EC, EVP_PKEY_DSA, EVP_PKEY_RSA

[08-11] Public key length(RSA)  // 항상 0, 이건 대체 왜 넣는지 모르겠음

[12-15] Private key length(RSA)

[16~  ] Private key data


소스에서 확인 (헤더(4byte) + 키타입(4byte) + 공개키길이(4byte) + 개인키길이(4byte) + 개인키)

* https://android.googlesource.com/platform/system/security/+/master/softkeymaster/keymaster_openssl.cpp




<16 byte 이후로는 ASN.1 구조로 구성되어 있음>

308204A4

020100

02820101

00B1CF6BDC79B~~~



[00-00] 0x30 : 00110000 => Class : 00, P/C : 1, 10000 : 16(SEQUENCE)

Octet 1Octet 2 onwards
8765432187654321
Tag classP/CTag number (0–30)N/A
31MoreTag number

[01-03] 0x820276

0x82 : 10000010 =>  Form : 1, Number : 0000010 

0x0276 : Length : 1166

FormBits
87654321
Definite, short0Length (0–127)
Indefinite10
Definite, long1Number of following octets (1–126)
Reserved1127


[04-06] 0x020100

0x02 : INTEGER

0x01 : Length - 1 byte

0x00 : Value - 0

Types, universal class
NameValue
encodings
Tag number
DecimalHexadecimal
End-of-Content (EOC)Primitive00
BOOLEANPrimitive11
INTEGERPrimitive22
BIT STRINGBoth33
OCTET STRINGBoth44
NULLPrimitive55
OBJECT IDENTIFIERPrimitive66
Object DescriptorBoth77
EXTERNALConstructed88
REAL (float)Primitive99
ENUMERATEDPrimitive10A
EMBEDDED PDVConstructed11B
UTF8StringBoth12C
RELATIVE-OIDPrimitive13D
Reserved14E
Reserved15F
SEQUENCE and SEQUENCE OFConstructed1610
SET and SET OFConstructed1711
NumericStringBoth1812
PrintableStringBoth1913
T61StringBoth2014
VideotexStringBoth2115
IA5StringBoth2216
UTCTimeBoth2317
GeneralizedTimeBoth2418
GraphicStringBoth2519
VisibleStringBoth261A
GeneralStringBoth271B
UniversalStringBoth281C
CHARACTER STRINGBoth291D
BMPStringBoth301E

[07-10] 0x02820101

0x02 : INTEGER

0x82 : Length - 2 byte

0x0101 : Value - 257


[11-267] : Private Key

00B1CF6BDC79B~~~


-----------------------------------------------------------------------------


openssl 을 이용하여서 RSA private key 의 ASN.1 포맷을 출력하여 분석한 예제는 다음과 같습니다.

 

# openssl.exe asn1parse -in key.pem -inform PEM
    0:d=0  hl=4 l= 603 cons: SEQUENCE
    4:d=1  hl=2 l=   1 prim: INTEGER           :00                                                                                 <- Version
    7:d=1  hl=3 l= 129 prim: INTEGER           :C6ACA7101D8D0E8D08C5AAA3947E2DE0                        <- Modulus
C708DA88017AD7276372B7745C0CB9ACD2A22E45438C472DBC81F62AAEE0521EE6DC283768D9C20C
C523B52478AF2B2ED9BCC7717BB25560E63FBA603A1C0E0351367CECFE45DB67EB50014031B4D652
4C95EA9B71819C175F17FCCAAB8DCE1B1F7D7BD24C211E210E1D5C2D91066163
  139:d=1  hl=2 l=   3 prim: INTEGER           :010001                                                                         <- Public Exponent
  144:d=1  hl=3 l= 128 prim: INTEGER           :2BACB2C1292DE41FFEE8AD3D6E9C5A6B                       <- Private Exponent
8A7598CCC33E84E3C4C9E8286D3FE2E56A1C7AFD80FEEA7AD470E173BAA3D789B1887E52C7FAEEDC
ADCDCEB968CA613C74EE6135AFA7EEAD72362A6DE12B2E2AD70208CFBDC2C8E87B472E93A725ECF0
027341BB873F0A14AA0DA5625373E529927E54E510D1E7A436CB68D1EA6AC781
  275:d=1  hl=2 l=  65 prim: INTEGER           :F3CEAEA8E9B862D9C19845E700EDC445                         <- Prime 1
0F9FF33A6274FFE527F5F6A4120E736BFC98CA4CD39AB3A9D418EFBBC8B9C995886E739CE66B09E8
6987474E6F262A41
  342:d=1  hl=2 l=  65 prim: INTEGER           :D09C292A5B2EE02EF4F7F92C33877724                          <- Prime 2
9A742865DA8388344F1CAB5EC58CD53121A462451C564BFE60781F45A2BB21439576118336A42D61
5821E0D1ECF6FAA3
  409:d=1  hl=2 l=  64 prim: INTEGER           :72949FE12276557EA14D3F0CE192DCBA                         <- Exponent 1
D82D03D25C933FF02267A61255AA14F49B31F36147D15CBE63BF946B5C5A7432A27BC639E6D04747
C2D0A0E26BBA3401
  475:d=1  hl=2 l=  64 prim: INTEGER           :794F8684D217B558B92E06E194699F78                          <- Exponent 2
52B55FD4B338B019333449D7C7EBB902643CF2C49BD0F74A4B112FA65016A0266C2107D8150B6E34
608AFAF138EAFB1F
  541:d=1  hl=2 l=  64 prim: INTEGER           :3D8D967868A0FA34D0622D33981C97C9                        <- Coefficient
493CD82CF234F587D398CF005BA7E9970D39AC3CFA6B161192A996377CD6AD7F2D28AFD5085114C1
15D34705A84447EE


<PKCS#1 개인키 구조>

-----BEGIN RSA PRIVATE KEY-----
RSAPrivateKey ::= SEQUENCE {
  version           Version,
  modulus           INTEGER,  -- n
  publicExponent    INTEGER,  -- e
  privateExponent   INTEGER,  -- d
  prime1            INTEGER,  -- p
  prime2            INTEGER,  -- q
  exponent1         INTEGER,  -- d mod (p-1)
  exponent2         INTEGER,  -- d mod (q-1)
  coefficient       INTEGER,  -- (inverse of q) mod p
  otherPrimeInfos   OtherPrimeInfos OPTIONAL
}
-----END RSA PRIVATE KEY-----

<참고자료>

https://etherhack.co.uk/asymmetric/docs/rsa_key_breakdown.html




공인인증서 오픈소스 파이썬 모듈

온라인 방정식(algebra) 계산기

hexdump 도구 대체 명령어

$
0
0

hexdump가 설치안된 곳에서 hex값을 출력할때 유용함


od -t x1 /data/system/gesture.key


od syntax

od [OPTION]... [FILE]...
od [-abcdfilosx]... [FILE] [[+]OFFSET[.][b]]
od --traditional [OPTION]... [FILE] [[+]OFFSET[.][b] [+][LABEL][.][b]]

Options

Note: all arguments to --long options are mandatory for -short options.

-A RADIX--address-radix=RADIXdecide how file offsets are printed
-j BYTES--skip-bytes=BYTESskip BYTES input bytes first
-N BYTES--read-bytes=BYTESlimit dump to BYTES input bytes
-S BYTES--strings[=BYTES]output strings of at least BYTES graphic chars
-t TYPE--format=TYPEselect output format or formats
-v--output-duplicatesdo not use * to mark line suppression
-w[BYTES], --width[=BYTES]output BYTES bytes per output line
--traditionalaccept arguments in traditional form
--helpdisplay help and exit
--versiondisplay version information and exit

Format Specifications

-asame as -t a, select named characters, ignoring high-order bit
-bsame as -t o1, select octal bytes
-csame as -t c, select ASCII characters or backslash escapes
-dsame as -t u2, select unsigned decimal 2-byte units
-fsame as -t fF, select floats
-isame as -t dI, select decimal ints
-lsame as -t dL, select decimal longs
-osame as -t o2, select octal 2-byte units
-ssame as -t d2, select decimal 2-byte units
-xsame as -t x2, select hexadecimal 2-byte units

If first and second call formats both apply, the second format is assumed if the last operand begins with "+" or (if there are 2 operands) a digit. An OFFSET operand means -j OFFSETLABEL is the pseudo-address at first byte printed, incremented when dump is progressing. For OFFSET and LABEL, a 0x or 0X prefix indicates hexadecimalsuffixesmay be "." for octal and b for multiply by 512.

TYPE is made up of one or more of these specifications:

anamed character, ignoring high-order bit
cASCII character or backslash escape
d[SIZE]signed decimal, SIZE bytes per integer
f[SIZE]floating point, SIZE bytes per integer
o[SIZE]octal, SIZE bytes per integer
u[SIZE]unsigned decimal, SIZE bytes per integer
x[SIZE]hexadecimal, SIZE bytes per integer

SIZE is a number. For TYPE in d/o/u/xSIZE may also be C for sizeof(char), S for sizeof(short), I for sizeof(int) or L for sizeof(long). If TYPE is fSIZE may also be F for sizeof(float), D for sizeof(double) or L for sizeof(long double).

RADIX is d for decimal, o for octal, x for hexadecimal or n for none. BYTES is hexadecimal with 0x or 0X prefix, and may have a multiplier suffix: b 512, kB 1000, K1024, MB 1000*1000, M 1024*1024, GB 1000*1000*1000, G 1024*1024*1024, and so on for TPEZY. Adding a z suffix to any type displays printable characters at the end of each output line. Option --string without a number implies 3; option --width without a number implies 32. By default, od uses -A o -t oS -w16.

안드로이드 제스처 및 PIN 해시 공격

Viewing all 46 articles
Browse latest View live