原宿工業大学 http://note.harajuku-tech.org HIT(Harajuku Institude of Technology : Harajuku-Tech ) posterous.com Thu, 17 May 2012 00:49:12 -0700 M2Crypto: Diffie-Hellman 鍵交換 http://note.harajuku-tech.org/m2crypto-diffie-hellman http://note.harajuku-tech.org/m2crypto-diffie-hellman

From Evernote:

M2Crypto: Diffie-Hellman 鍵交換

共通パラメータ(prime,generator)を作成
>>> from M2Crypto import DH
>>> shared=DH.load_params('/tmp/hogehoge.pem')

Aliceがキーを作成
>>> alice_dh = DH.set_params(shared.p,shared.g)
>>> alice_dh.gen_key()
>>> alice_dh.pub
'\x00\x00\x00\x80H\x11J\xc4\x83Y\xc8o\x0f1g\x9d\xe3Gw\xf1\xae\xc6\x8aL\xb4\xd6N\x90\x97+\xc1]\x10\xed\x91\xd2Fj\xdcwD\x1cTP\xf4\xa3\xa7S\xceT.\xf1k\x90\xd5\x89L\xd6\xdb\xff\xbdHY\xee\xad6\x81\x16H\xf9\xc3\xe0\xd9o\xcd\xe7\x8dt\xe6\xf5Z\xd0,\xfb{*\xc2D\xc6\xd9\xe3\xb9W\x018n\x05\x16l\xa8@\xc2\x07Q\x0b\xc2\x8d\x1b\xe7\x9e{\xb3}\xee\xed\xa1x\x03w\xe8LY\xba1\x8eN\x17\x16\xe4\x0bf\x9e'

Bobがキーを作成
>>> bob_dh=DH.set_params(shared.p,shared.g)
>>> bob_dh.gen_key()   
'\x00\x00\x00\x80\x04\x1e1\xcd\xca\xfcn\xc3\x16i\xa4\x95C\xdf\\\xe9O\xdfQ\x81~\xd5\x1d(\x08\xc5\x91\xd3\x9fdt\x93\x9fix\x12b\xed\xfcK\xb3\xcb\xba\xc2\xde\xb5\x83\x1b.^_\xccgZ\xe9)\'\x14\xf4\xe6\x13o\x8f\xe7\x9d@?\xf4\xe6(a_q6A&K\xf4\x1d\xef6\xefz\xf2\x1b.h\xfc\x171\x91\xbfQ\x01\xb4\x98\xf9\xc5\x82\x8c\xf0\x96"\x84\x92\x13{\xc3\x9e[-\xe8_\xa4\'\xe6\x87\x07u\xdf\xc2\xc2\xe1\x1c\x1e\x89\x9d\xf7'

公開鍵はお互い違います

>>> alice_dh.pub != bob_dh.pub
True

相手の公開鍵をつかって生成した値は同じです

>>> alice_dh.compute_key(bob_dh.pub) == bob_dh.compute_key(alice_dh.pub)
True

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/42987/2927948561_7ed7debbf0_s.jpg http://posterous.com/users/PTLDXNYAAV hide lafoglia hdknr hide lafoglia
Thu, 17 May 2012 00:02:14 -0700 OpenSSL : Diffie-Hellman パラメータを1024ビット素数長でPEMに書き出す http://note.harajuku-tech.org/openssl-diffie-hellman-1024pem http://note.harajuku-tech.org/openssl-diffie-hellman-1024pem

From Evernote:

OpenSSL : Diffie-Hellman パラメータを1024ビット素数長でPEMに書き出す

(docs)Peeko:identity hide$ openssl dhparam -outform PEM -out /tmp/hogehoge.pem 1024

Generating DH parameters, 1024 bit long safe prime, generator 2
This is going to take a long time.....................................................................................+
..................................................................................................++*++*++*

(docs)Peeko:identity hide$ openssl dhparam -outform PEM -out /tmp/hogehoge2.pem 1024
Generating DH parameters, 1024 bit long safe prime, generator 2This is going to take a long time
.....................................................+.......................................................+...........+.........….
.............................................................................................................................................…
.......+..............................+...+.........................+.............................................+...................+…..
..................+.+.....................+...............+..............................................................................…..
................................................................…
.....................+....................................................................+.....................+..........+............….
..........+......................................................................................+..........................................….
.......................................+.............
.......+..+.................................+..............................+........+..+....+..........................................…
......................
...........++*++*++*

(docs)Peeko:identity hide$ diff /tmp/hogehoge.pem /tmp/hogehoge2.pem 
2,4c2,4
< MIGHAoGBAO21tpvkuvK1knEo5SLfkdphxr+bjtk0+auEpUf3Mv95pNdbgKFrBoWZ
< rv2zvhZmJpEoY5ZmQ6KCZ5HM38dIOfU0RqLbpO7yxXqfh9/zkz6SC1mSPYnEYIRX
< tRYPybdOVbcPNWF99FlMe+ZDrmZbo8T4Os3zVDvoIgjCouCXjruDAgEC
---
> MIGHAoGBALlj1eXPCWfIco5PRtQHvnRmvzbaagg4cjerHXtkOtDPFUWFAnRHdmAv
> g5Y79GGYDUlhpgN6HYH7Bl4LNXymCD1oK/0/GtbTTOtTtr4NKGAI5bXg3YDvHaeS
> Dc9FEXnOVz32VwlR+yNymt30nco4UOHdoC++hSLVSAzkMqQrngbTAgEC

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/42987/2927948561_7ed7debbf0_s.jpg http://posterous.com/users/PTLDXNYAAV hide lafoglia hdknr hide lafoglia
Thu, 17 May 2012 00:01:41 -0700 M2Crypto: DH パラメータ作成 http://note.harajuku-tech.org/m2crypto-dh http://note.harajuku-tech.org/m2crypto-dh

From Evernote:

M2Crypto: DH パラメータ作成

>>> from M2Crypto import DH

>>> DH.DH_GENERATOR_2
2
>>> DH.DH_GENERATOR_5
5

>>> DH.m2
<module 'M2Crypto.m2' from '/Users/hide/ve/docs/lib/python2.7/site-packages/M2Crypto/m2.pyc'>
(SWIG の OpenSSLラッパー )

>>> def _callback(*args):
...    pass
… 
>>> alice=DH.gen_params(1024,2,_callback)
>>> alice
<M2Crypto.DH.DH instance at 0x100cb1518>

>>> alice.check_params() == 0
True

>>> dir(alice)
['__del__', '__doc__', '__getattr__', '__init__', '__len__', '__module__', '__setattr__', '_ptr', '_pyfree',
 'check_params', 'compute_key', 'dh', 'gen_key', 'm2_dh_free', 'print_params']

BIO=OpenSSLの抽象化I/O
>>> from M2Crypto import BIO
>>> bio=BIO.MemoryBuffer()
>>> bio
<M2Crypto.BIO.MemoryBuffer instance at 0x100cb15f0>

>>> alice.print_params(bio)
1
>>> bio
<M2Crypto.BIO.MemoryBuffer instance at 0x100cb15f0>
>>> out=bio.read()

>>> type(out)
<type 'str'>
>>> print out
Diffie-Hellman-Parameters: (1024 bit)
    prime:
        00:c4:b4:b7:d3:22:34:03:82:21:70:d8:31:14:2b:
        f1:7b:89:53:2d:5c:d7:a2:42:fd:b0:6e:a5:17:bf:
        7a:35:5f:26:f9:9d:f9:95:fa:ca:da:0b:20:eb:24:
        2e:8e:31:96:c6:7e:fc:e0:8a:58:45:23:b5:fc:8a:
        13:63:6b:03:84:ed:72:78:e8:b9:60:8a:62:78:a8:
        c6:ae:90:a5:9c:60:cc:c8:d7:e1:30:6d:e1:ce:54:
        e7:e6:7f:ce:cb:44:0c:5b:3b:de:96:44:9d:74:2a:
        a6:f5:d9:35:8f:d0:39:30:e8:58:f3:26:a6:b0:2b:
        33:f5:e2:b0:1b:45:0d:95:6b
    generator: 2 (0x2)

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/42987/2927948561_7ed7debbf0_s.jpg http://posterous.com/users/PTLDXNYAAV hide lafoglia hdknr hide lafoglia
Tue, 15 May 2012 21:30:00 -0700 vim : Vundle インストール http://note.harajuku-tech.org/vim-vundle http://note.harajuku-tech.org/vim-vundle

From Evernote:

vim : Vundle インストール

treeコマンドをHomebrew でMacBook に入れる

Peeko:~ hide$ brew info tree

tree 1.6.0
Not installed

Peeko:~ hide$ brew home tree

281db0667a7f59d96b66dd22fa55c4

Peeko:~ hide$ brew install tree

######################################################################## 100.0%
==> make prefix=/usr/local/Cellar/tree/1.6.0 MANDIR=/usr/local/Cellar/tree/1.6.0/share/man/man1 CC=/usr/bin/clang CFLAGS=-Os -w -pipe -march=native -Qunused-arguments
/usr/local/Cellar/tree/1.6.0: 6 files, 112K, built in 7 seconds

.vim 作り直し& vundle インストール

Peeko:.vim hide$ cd
Peeko:~ hide$ mv .vim .vim.bak
Peeko:~ hide$ mkdir .vim ; cd .vim
Peeko:.vim hide$ git clone git://github.com/gmarik/vundle.git
Cloning into 'vundle'...
remote: Counting objects: 2349, done.
remote: Compressing objects: 100% (1511/1511), done.
remote: Total 2349 (delta 785), reused 2302 (delta 747)
Receiving objects: 100% (2349/2349), 283.96 KiB | 151 KiB/s, done.
Resolving deltas: 100% (785/785), done.

.vimrc 編集

Peeko:.vim hide$ cd
Peeko:~ hide$ vi .vimrc

  3 filetype off
  4
  5 "-----  Vundle
  6 set rtp+=~/.vim/vundle/
  7 call vundle#rc()
  8
  9 Bundle 'thinca/vim-ref'
 10 Bundle 'tpope/vim-surround'
 11 Bundle 'mattn/gist-vim'
 12 "Bundle 'Shougo/neocomplcache'
 13 "Bundle 'Shogo/unite.vim'
 14 "Bundle 'scrooloose/nerdcommenter'
 15 "Bundle 'thinca/vim-puickrun'
 16 "Bundle 'kana/vim-fakeclip'


プラグインインストール前

Peeko:~ hide$ tree .vim
.vim
└── vundle
    ├── LICENSE-MIT.txt
    ├── README.md
    ├── autoload
    │   ├── vundle
    │   │   ├── config.vim
    │   │   ├── installer.vim
    │   │   └── scripts.vim
    │   └── vundle.vim
    ├── doc
    │   └── vundle.txt
    └── test
        ├── minirc.vim
        └── vimrc

5 directories, 9 files


vim 起動
C1252d6bb75af11da1d2475d445ef1
:BundleInstall

1ff6fbf5fffc3433baaf89f8024aaa

インストール状況&終了
Af8564f12fb40157b2e754c370964c


プラグインインストール後

.vim
├── bundle
│   ├── gist-vim
│   │   ├── Makefile
│   │   ├── README.mkd
│   │   ├── autoload
│   │   │   └── gist.vim
│   │   ├── doc
│   │   │   ├── gist-vim.txt
│   │   │   └── tags
│   │   ├── gist.vim.vimup
│   │   └── plugin
│   │       └── gist.vim
│   ├── vim-ref
│   │   ├── autoload
│   │   │   ├── ku
│   │   │   │   └── ref.vim
│   │   │   ├── ref
│   │   │   │   ├── clojure.vim
│   │   │   │   ├── erlang.vim
│   │   │   │   ├── man.vim
│   │   │   │   ├── perldoc.vim
│   │   │   │   ├── phpmanual.vim
│   │   │   │   ├── pydoc.vim
│   │   │   │   ├── refe.vim
│   │   │   │   ├── rfc.vim
│   │   │   │   └── webdict.vim
│   │   │   ├── ref.vim
│   │   │   └── unite
│   │   │       ├── kinds
│   │   │       │   └── ref.vim
│   │   │       └── sources
│   │   │           └── ref.vim
│   │   ├── doc
│   │   │   ├── ku-ref.txt
│   │   │   ├── ref-clojure.jax
│   │   │   ├── ref-clojure.txt
│   │   │   ├── ref-erlang.jax
│   │   │   ├── ref-erlang.txt
│   │   │   ├── ref-man.jax
│   │   │   ├── ref-man.txt
│   │   │   ├── ref-perldoc.jax
│   │   │   ├── ref-perldoc.txt
│   │   │   ├── ref-phpmanual.jax
│   │   │   ├── ref-phpmanual.txt
│   │   │   ├── ref-pydoc.jax
│   │   │   ├── ref-pydoc.txt
│   │   │   ├── ref-refe.jax
│   │   │   ├── ref-refe.txt
│   │   │   ├── ref-webdict.jax
│   │   │   ├── ref.jax
│   │   │   ├── ref.txt

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/42987/2927948561_7ed7debbf0_s.jpg http://posterous.com/users/PTLDXNYAAV hide lafoglia hdknr hide lafoglia
Tue, 15 May 2012 05:00:00 -0700 すぐに出来る!! vundleでモダンなvim環境を作ろう - (゚∀゚)o彡 sasata299's blog http://note.harajuku-tech.org/-vundlevim-o-sasata299s-blog http://note.harajuku-tech.org/-vundlevim-o-sasata299s-blog
どうやったら使える?

インストールと使い方もすごく簡単です。まずインストールは git clone するだけです。.vim の下に clone してあげてください。

 

1
git clone http://github.com/gmarik/vundle.git ~/.vim/vundle.git

ただ dotfiles をすでに git で管理しているような環境だと vundle は外部リポジトリとして追加してあげた方が良さそうです。こんな感じですかね。

 

1
2
3
4
cd dotfiles # リポジトリに移動する
git submodule add http://github.com/gmarik/vundle.git .vim/vundle.git
git add .
git commit -m "add vundle submodule"

あとは使いたいプラグインを .vimrc にちょろっと書いてあげるだけで使えるようになります。プラグインは .vimrc にこのように Bundle "plugin_name" と記述するだけ。.vimrc で使っているプラグインが一元管理できるのはすごく楽ですね~。

あ、4, 5行目はおまじないです。詳しくは こちら を参照ください。

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
set nocompatible
filetype off

 

set rtp+=~/.vim/vundle.git/
call vundle#rc()

 

" vim-scripts リポジトリ (1)
Bundle "rails.vim"

 

" github の任意のリポジトリ (2)
Bundle "tpope/vim-fugitive"

 

" github 以外のリポジトリ (3)

 

filetype plugin indent on

使いたいプラグインを指定するわけですが、プラグインの置かれている場所によって3つの方法があります。vim-scripts リポジトリ (http://vim-scripts.org/vim/scripts.html) に置かれていれば (1) のようにプラグイン名を、github の任意のリポジトリであれば (2) のようにリポジトリ名とプラグイン名を、github のリポジトリでは無い場合には (3) のようにフルパスで指定します。

で、最後に vim 上で :BundleInstall することで、プラグインが .vim/bundle 以下にさくっとインストールされます。あっという間です。もう使えます!!

 

 

 

 

 

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/42987/2927948561_7ed7debbf0_s.jpg http://posterous.com/users/PTLDXNYAAV hide lafoglia hdknr hide lafoglia
Mon, 14 May 2012 13:57:00 -0700 How to set up Windows Media Services 9 Series to use HTTP streaming on port 80 with IIS 6.0 installed http://note.harajuku-tech.org/how-to-set-up-windows-media-services-9-series http://note.harajuku-tech.org/how-to-set-up-windows-media-services-9-series
If either of these conditions is true, follow these steps to configure the listener:
  1. From a command prompt, type the appropriate command to stop the following services:
    • Windows Media Services: net stop wmserver
    • Internet Information Services: net stop iisadmin
    • Http.sys Listener: net stop http
  2. Run the WMSHttpSysCfg utility (located at %systemroot%\system32\windows media\server\admin\mmc\WMSHttpSysCfg.exe).
  3. Add the IP addresses that you want Http.sys to listen to. The addresses that Http.sys does not listen to are available for WMS to use. (If this list is blank, Http.sys listens to all non-loopback IP addresses).
  4. Click OK to close the dialog box.
  5. Restart the services that you stopped in step 1 (including, but not limited to):
    • Http.sys Listener: net start http
    • World Wide Web Publishing Service or IIS Admin: net start w3svc
    • Windows Media Services: net start wmserver
  6. Configure WMS HTTP Server Control Protocol:
    1. Start WMS Admin MMC.
    2. Select the server name.
    3. Click the Properties tab, and then click Control Protocols.
    4. If it is not already disabled (or if it is In Error), right-click WMS HTTP Server Control Protocol, and then click Disable.
    5. Right-click WMS HTTP Server Control Protocol, and then click Properties.
    6. Click Allow selected IP addresses to use this protocol.
    7. Select the IP addresses that you want to deliver content over port 80.

      Note Do not select the same IP addresses as the ones that you added to the Http.sys listener in step 3, otherwise the plug-in might go into an error state when it is enabled.

    8. Set the plug-in to Use default port (80).
    9. Click Apply, and then click OK to close the dialog box.
    10. Right-click WMS HTTP Server Control Protocol, and then click Enable.
At this point, you can expect that WMS is streaming media content over port 80 for the IPs selected in the control plug-in, and that Http.sys is handling all other port 80 requests.

Important Other applications might make a configuration utility that can change the Http.sys IP listen list. When you restart the Http.sys service the next time, it can bind to port 80 on an address selected by WMS and might cause the control plug-in to go into an error state.

If you are using Microsoft Windows Server 2003 with Service Pack 1 installed, you can also prevent the Http.sys service from capturing all available IP addresses for port 80 by applying the hotfix that is mentioned in the following Microsoft Knowledge Base article:

892847  (http://support.microsoft.com/kb/892847/ ) FIX: IIS 6.0 incorrectly binds to ports when IP addresses are added to the IP inclusion list
This hotfix lets you set a registry value that makes the Http.sys service listen only to the specific IP addresses that IIS Web sites are configured to use.

For more information about running Windows Media Services v4.1 with IIS 5.0, click the following article number to view the article in the Microsoft Knowledge Base:

268585  (http://support.microsoft.com/kb/268585/ ) Running IIS 5.0 and Windows Media Services with HTTP streaming

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/42987/2927948561_7ed7debbf0_s.jpg http://posterous.com/users/PTLDXNYAAV hide lafoglia hdknr hide lafoglia
Mon, 14 May 2012 02:33:00 -0700 Django | Aggregation | Django documentation http://note.harajuku-tech.org/django-aggregation-django-documentation-75134 http://note.harajuku-tech.org/django-aggregation-django-documentation-75134

As with aggregate(), the name for the annotation is automatically derived from the name of the aggregate function and the name of the field being aggregated. You can override this default name by providing an alias when you specify the annotation:

>>> q = Book.objects.annotate(num_authors=Count('authors'))
>>> q[0].num_authors
2
>>> q[1].num_authors
1

ここは、 aggregate()ではなくて annotate() のような気がします。。。

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/42987/2927948561_7ed7debbf0_s.jpg http://posterous.com/users/PTLDXNYAAV hide lafoglia hdknr hide lafoglia
Mon, 14 May 2012 01:02:25 -0700 VirtualBox : 古いMacからイメージを移動してブートしない時 http://note.harajuku-tech.org/virtualbox-mac http://note.harajuku-tech.org/virtualbox-mac

From Evernote:

VirtualBox : 古いMacからイメージを移動してブートしない時

旧Macから新MacにLenny のイメージを持ってきてブート

721f6d61fd6a4f4df32abeb476d07f

デバイスがhda->sdaに変更になっているので、CTRL+ALT+DELでgrub 編集(e)

8e96d2d3b6d5318537f7c932ea53be

ブートした。ので、
deblen:~#  vi /boot/grub/grub.conf 
F172aaca5d4a89eda0cf32e23b56a6

/etc/fstabも。 デバイス名がわからんので、

deblen:~# cfdisk

D2ab028e53a2b29b521c8b01244298

swapon  -a / free で確認.

64a55b7034b8264ce9914a4ce7f4f5

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/42987/2927948561_7ed7debbf0_s.jpg http://posterous.com/users/PTLDXNYAAV hide lafoglia hdknr hide lafoglia
Sun, 13 May 2012 09:16:00 -0700 VirualBoxで仮想マシン(CentOS6)の複製したらネットワークが起動しない。(エラー:device eth0 does not seem to be present, delaying initialization) : Edo::World::Blog http://note.harajuku-tech.org/virualboxcentos6device-eth0-does-not-seem-to http://note.harajuku-tech.org/virualboxcentos6device-eth0-does-not-seem-to

対応法:

ココに記載があった。

ようはudevの設定を変更しろっ、との事

# vi /etc/udev/rules.d/70-persistent-net.rules
※こいつは複製前の情報なので削除
# PCI device 0x8086:0x100e (e1000) (custom name provided by external tool)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="08:00:27:fb:41:ae", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"

※こっちが複製後のMACアドレスがセットされている(違ったら修正)。ただし、"NAME="eth1"を"NAME=eth0"に変更する必要
# PCI device 0x8086:0x100e (e1000)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="08:00:27:9f:cc:8d", ATTR{type}=="1", KERNEL=="eth*", NAME="eth1"


# reboot   ※再起動してネットワークの稼働状況を確認

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/42987/2927948561_7ed7debbf0_s.jpg http://posterous.com/users/PTLDXNYAAV hide lafoglia hdknr hide lafoglia
Thu, 10 May 2012 02:40:00 -0700 .NET で X.509 証明書を読み込む: DERだったら読めるということです http://note.harajuku-tech.org/net-x509-der http://note.harajuku-tech.org/net-x509-der

From Evernote:

.NET で X.509 証明書を読み込む: DERだったら読めるということです

127         public static  byte[] GetBytesFromPEM(string pemString, string section="CERTIFICATE")
128         {
129             var header = String.Format("-----BEGIN {0}-----", section);
130             var footer = String.Format("-----END {0}-----", section);
131
132             var start = pemString.IndexOf(header, StringComparison.Ordinal) + header.Length;
133             var end = pemString.IndexOf(footer, start, StringComparison.Ordinal) - start;
134
135             if (start < 0 || end < 0)
136             {
137                 return null;
138             }
139
140             return Convert.FromBase64String(pemString.Substring(start, end));
141         }
142
143         public static System.Security.Cryptography.X509Certificates.X509Certificate2
144                 GetCertificateFromPEM(string pemString, string section = "CERTIFICATE")
145         {
146
147             return new System.Security.Cryptography.X509Certificates.X509Certificate2(
148                     GetBytesFromPEM(pemString,section )
149                 );
150         }


NUnit

268         [Test]
269         public void MsCertificate()
270         {
271             var op = GetOp();
272
273             var cert = Jose.Jws.GetCertificateFromPEM(op.x509_cache);
274
275             Console.WriteLine(cert.FriendlyName);
276             Console.WriteLine(cert.Issuer);
277             Console.WriteLine(cert.SubjectName.Name);
278 

B5142669ba9127277ef636a2f90f10

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/42987/2927948561_7ed7debbf0_s.jpg http://posterous.com/users/PTLDXNYAAV hide lafoglia hdknr hide lafoglia
Wed, 09 May 2012 20:23:41 -0700 M2Crypto: Sign/Verify with X.509 / RSA-SHA-256 http://note.harajuku-tech.org/m2crypto-signverify-with-x509-rsa-sha-256 http://note.harajuku-tech.org/m2crypto-signverify-with-x509-rsa-sha-256

From Evernote:

M2Crypto: Sign/Verify with X.509 / RSA-SHA-256

>>> from M2Crypto import RSA
>>> pk=RSA.load_key('server.key')

>>> import hashlib
>>> digest = hashlib.sha256( "ABCDEFGHIJKLMN" ).digest()
>>> digest
'\x93\xc5\xf0\x07"\x0b8\xab%tV\xa0\xe9e@\xd1H\xd4B\\\xf9\x15i\xdb\xcd\xfekrhU8\xa4'
>>> signature=pk.sign(digest) 
>>> signature
"\x9a\xcd\xf0\xd0?\x9e\xfeA\xeebQ\x97\x15D …….

>>> from M2Crypto import X509
>>> pub=X509.load_cert('server.crt').get_pubkey().get_rsa()                                                                                                                 
>>> pub
<M2Crypto.RSA.RSA_pub instance at 0xbe1290>

>>> pub.verify(hashlib.sha256("ABCDEFGHIJKLMN").digest(),signature)
1

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/42987/2927948561_7ed7debbf0_s.jpg http://posterous.com/users/PTLDXNYAAV hide lafoglia hdknr hide lafoglia
Wed, 09 May 2012 20:00:00 -0700 Choosing an API framework for Django http://note.harajuku-tech.org/choosing-an-api-framework-for-django http://note.harajuku-tech.org/choosing-an-api-framework-for-django

django-tastypie

Using django-tastypie is like playing with pure Python while using the Django ORM. I find it very comfortable. Seems really fast too. The documentation is incredible, and I rarely have any problems figuring anything out. It also supports OAuth 1.0a out of the box, which is mighty awesome these days.

In fact, I wrote a custom OAuth2 handler for django-tastypie I wrote for consumer.io that I'm working to extract out for publication.

django-rest-framework

As it's based off Django 1.3 style Class Based Views (CBVs), it has a very familiar pattern. Actually, because of the quality of the documentation, I really prefer using django-rest-framework CBVs more than using Django's actual CBVs.

Maybe I should make an HTML renderer for django-rest-framework? :-)

But what about django-piston?

Don't use django-piston.

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/42987/2927948561_7ed7debbf0_s.jpg http://posterous.com/users/PTLDXNYAAV hide lafoglia hdknr hide lafoglia
Wed, 09 May 2012 18:54:00 -0700 Travis CI http://note.harajuku-tech.org/travis-ci http://note.harajuku-tech.org/travis-ci

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/42987/2927948561_7ed7debbf0_s.jpg http://posterous.com/users/PTLDXNYAAV hide lafoglia hdknr hide lafoglia
Wed, 09 May 2012 11:50:00 -0700 M2Crypto.RSA.RSA : sign() http://note.harajuku-tech.org/m2cryptorsarsa-sign http://note.harajuku-tech.org/m2cryptorsarsa-sign

sign(self, digest, algo='sha1')

 

Signs a digest with the private key

Parameters:
  • digest (str) - A digest created by using the digest method
  • algo (str) - The method that created the digest. Legal values are 'sha1','sha224', 'sha256', 'ripemd160', and 'md5'.
Returns:
a string which is the signature

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/42987/2927948561_7ed7debbf0_s.jpg http://posterous.com/users/PTLDXNYAAV hide lafoglia hdknr hide lafoglia
Wed, 09 May 2012 03:18:00 -0700 Git で不要になったローカルブランチ・リモートブランチの削除 - sotarokのお勉強 http://note.harajuku-tech.org/git-sotarok http://note.harajuku-tech.org/git-sotarok
% git branch -a
* master
  hoge
  origin/hoge
% git branch -d hoge
% git push origin :hoge

:hoge でリモートブランチの削除になるの。

わかりづらい気がするよ!

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/42987/2927948561_7ed7debbf0_s.jpg http://posterous.com/users/PTLDXNYAAV hide lafoglia hdknr hide lafoglia
Wed, 09 May 2012 01:33:00 -0700 Amazon Elastic Block Store (EBS) http://note.harajuku-tech.org/amazon-elastic-block-store-ebs http://note.harajuku-tech.org/amazon-elastic-block-store-ebs

共有スナップショットの使い方

スナップショットは、AWS Management Console またはAPI 呼び出しを使って共有できます。ユーザーは、AWS コミュニティ全体で共有するオプションを含めて、共有スナップショット別に設定することができます。

AWS Management Console:

  1. 新しい Amazon EBS ボリュームを作成してそのボリュームで共有するファイルのみをコピーします。
  2. AWS Management Console にログインし、[Amazon EC2] タブをクリックしてから、左側のナビゲーションペインにある [ボリューム] をクリックします。
  3. [ボリューム] を右クリックしてスナップショットをとります。
  4. 左側のナビゲーションペインで [スナップショット] をクリックします。
  5. 共有する [スナップショット] を右クリックして、[スナップショットアクセス許可] を選択します。
  6. アクセスを許可する開発者の AWS アカウント番号を追加する、または公開して共有します。
  7. [保存] をクリックしてアクセス許可を適用します。

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/68107/gentoo-transparent-small.png http://posterous.com/users/1gDCcBTnh4Z noten skk ssk noten skk
Tue, 08 May 2012 00:27:00 -0700 BouncyCastle: RSA-SHA-256 をOpenSSLで作成したPEM形式のプライベートキーと証明書でできるようになった http://note.harajuku-tech.org/bouncycastle-rsa-sha-256-opensslpem-tagsbounc http://note.harajuku-tech.org/bouncycastle-rsa-sha-256-opensslpem-tagsbounc
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

using System.Security.Cryptography;

using Org.BouncyCastle.OpenSsl;
using Org.BouncyCastle.Crypto;
using Org.BouncyCastle.Crypto.Signers;
using Org.BouncyCastle.Crypto.Digests;
using Org.BouncyCastle.Crypto.Generators;
using Org.BouncyCastle.Crypto.Parameters;
using Org.BouncyCastle.X509;
using Org.BouncyCastle.Security;


namespace Sample
{
    public class Jws
    {
        public static AsymmetricCipherKeyPair GenerateKeys(int keySize)
        {
            var gen = new RsaKeyPairGenerator();
            var secureRandom = new SecureRandom();
            var keyGenParam = new KeyGenerationParameters(secureRandom, keySize);
            gen.Init(keyGenParam);
            return gen.GenerateKeyPair();
        }

        public static byte[] GetSignature(string plainText, RsaKeyParameters privateKey)
        {
            var encoder = new ASCIIEncoding();
            var inputData = encoder.GetBytes(plainText);

            var signer = SignerUtilities.GetSigner("SHA256WithRSAEncryption");
            signer.Init(true, privateKey);
            signer.BlockUpdate(inputData, 0, inputData.Length);

            return signer.GenerateSignature();
        }

        public static RsaKeyParameters RsaPrivateKeyFromPem(string private_key )
        {

            TextReader r = new StringReader(private_key);
            PemReader pem = new PemReader(r);
            return (RsaKeyParameters)((AsymmetricCipherKeyPair )pem.ReadObject()).Private;

        }
        public static RsaKeyParameters RsaPublicKeyFromPemCertificate(string certificate)
        {
            TextReader c = new StringReader(certificate);
            PemReader pem2 = new PemReader(c);
            X509Certificate x509 = (X509Certificate)pem2.ReadObject();

            return (RsaKeyParameters)x509.GetPublicKey();        
        }

        public static byte[] GetSignature(string plainText, string  pem_private_key)
        {
            return GetSignature(plainText,RsaPrivateKeyFromPem(pem_private_key));
            
        }


        public static bool VerifySignature(RsaKeyParameters publicKey, string plainText, byte[] signature)
        {
            var encoder = new ASCIIEncoding();
            var inputData = encoder.GetBytes(plainText);
            var signer = SignerUtilities.GetSigner("SHA256WithRSAEncryption");
            signer.Init(false, publicKey);
            signer.BlockUpdate(inputData, 0, inputData.Length);
            return signer.VerifySignature(signature);
        }

        public static bool VerifySignature(string pem_publicKey, string plainText, byte[] signature)
        {
            return VerifySignature(RsaPublicKeyFromPemCertificate(pem_publicKey), plainText, signature);
        } 


    }
}

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/42987/2927948561_7ed7debbf0_s.jpg http://posterous.com/users/PTLDXNYAAV hide lafoglia hdknr hide lafoglia
Mon, 07 May 2012 07:45:00 -0700 PHP: Error Messages Explained - Manual http://note.harajuku-tech.org/php-error-messages-explained-manual http://note.harajuku-tech.org/php-error-messages-explained-manual

Error Messages Explained

Since PHP 4.2.0, PHP returns an appropriate error code along with the file array. The error code can be found in the error segment of the file array that is created during the file upload by PHP. In other words, the error might be found in $_FILES['userfile']['error'].

UPLOAD_ERR_OK

Value: 0; There is no error, the file uploaded with success.

UPLOAD_ERR_INI_SIZE

Value: 1; The uploaded file exceeds the upload_max_filesize directive in php.ini.

UPLOAD_ERR_FORM_SIZE

Value: 2; The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form.

UPLOAD_ERR_PARTIAL

Value: 3; The uploaded file was only partially uploaded.

UPLOAD_ERR_NO_FILE

Value: 4; No file was uploaded.

UPLOAD_ERR_NO_TMP_DIR

Value: 6; Missing a temporary folder. Introduced in PHP 4.3.10 and PHP 5.0.3.

UPLOAD_ERR_CANT_WRITE

Value: 7; Failed to write file to disk. Introduced in PHP 5.1.0.

UPLOAD_ERR_EXTENSION

Value: 8; A PHP extension stopped the file upload. PHP does not provide a way to ascertain which extension caused the file upload to stop; examining the list of loaded extensions with phpinfo() may help. Introduced in PHP 5.2.0.

Note:

These became PHP constants in PHP 4.3.0.

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/42987/2927948561_7ed7debbf0_s.jpg http://posterous.com/users/PTLDXNYAAV hide lafoglia hdknr hide lafoglia
Mon, 07 May 2012 07:29:00 -0700 error handling - PHP's white screen of death - Stack Overflow http://note.harajuku-tech.org/error-handling-phps-white-screen-of-death-sta http://note.harajuku-tech.org/error-handling-phps-white-screen-of-death-sta
ini_set('error_reporting', E_ALL);
ini_set
('display_errors', 'On');  //On or Off

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/42987/2927948561_7ed7debbf0_s.jpg http://posterous.com/users/PTLDXNYAAV hide lafoglia hdknr hide lafoglia
Mon, 07 May 2012 07:23:00 -0700 Fix ‘Blank page’ problem aka White Screen of Death | am i works? http://note.harajuku-tech.org/fix-blank-page-problem-aka-white-screen-of-de http://note.harajuku-tech.org/fix-blank-page-problem-aka-white-screen-of-de

Their are two ways to get out of this situation,

  1. Changes in php.ini file

If you can have access to php.ini file then change the display error property to On.

display_errors = On

Also make sure that error reporting property is at least set to

error_reporting  =  E_ALL & ~E_NOTICE & ~E_STRICT
  1. Changes in the file

In case where you don’t have access to php.ini file, you can set these property in PHP script itself. Simply add following at the very start of your PHP script

error_reporting(E_ALL);
ini_set('display_errors',TRUE);

If you are using some, open source package like Drupal, Joomla or WordPress then put these codes in the index.php file in the root directory, right at top.

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/42987/2927948561_7ed7debbf0_s.jpg http://posterous.com/users/PTLDXNYAAV hide lafoglia hdknr hide lafoglia