Tue, 20 Dec 2016
Some time ago I had begun work on my own Pastebin-type project with a few goals. Basically, I wanted to eat all the cakes — and have them too.
Both an online user interface and efficient CLI usage
Messages encrypted immediately such that database access does not provide one with the contents of the messages
Messages capable of self-destructing
Database schema that would allow rebuilding the user/message relationship, provided the same password but would not store those relationships
Also, JavaScript encryption to appeal to users who don’t know much about cryptography but would like to try
The project, honestly, was going swimmingly when derailed by the goings-on of life.
One of the interesting components of the project was, of course, choosing crypto implementations. There are know shortcomings to handling it in JS but that’s still the most convenient for some users. Outside of the browser, server-side, you had all the same questions about which solution was best. Which protocol(s) should be available?
Well, I’ve just learned about a project which I would have loved to have available back then. Project Wycheproof can help you test your crypto solutions against known problems and attacks. Featuring 80 tests probing at 40 known bugs, here’s a snip from the introduction:
Project Wycheproof has tests for the most popular crypto algorithms, including
AES-EAXAES-GCM
AES-GCM
DH
DHIES
DSA
ECDH
ECDSA
ECIES
RSA
The tests detect whether a library is vulnerable to many attacks, including
Invalid curve attacks
Biased nonces in digital signature schemes
Of course, all Bleichenbacher’s attacks
And many more — we have over 80 test cases
Interesting stuff with exciting potential!
Tags: Bazel, Cryptography, Java
Permalink: 20161220.kicking.the.crypto.tires
Mon, 17 Feb 2014
Prereqruisites: Docker, Git, SSHFS.
Today we’re going to look at using Docker to create a WordPress installation with the Project Largo parent theme and a child theme stub for us to play with.
Hart Hoover has established an image for getting a WordPress installation up and running using Docker. For whatever reason, it didn’t work for me out-of-box but we’re going to use his work to get started.
Let’s make a place to work and move into that directory:
cd ~
mkdir project.largo.wordpress.docker
cd project.largo.wordpress.docker
We’ll clone the Docker/Wordpress project. For me, it couldn’t untar the latest WordPress. So we’ll download it outside the container, untar it and modify the Dockerfile to simply pull in a copy:
git clone https://github.com/hhoover/docker-wordpress.git
cd docker-wordpress/
ME=$(whoami)
wget http://wordpress.org/latest.tar.gz
tar xvf latest.tar.gz
sed -i 's/ADD http:\/\/wordpress.org\/latest.tar.gz \/wordpress.tar.gz/ADD \.\/wordpress \/wordpress/' Dockerfile
sed -i '/RUN tar xvzf \/wordpress\.tar\.gz/d' Dockerfile
Then, build the project which may take some time.
sudo docker build -t $ME/wordpress .
If you’ve not the images ready for Docker, the process should begin with something like:
Step 0 : FROM boxcar/raring
Pulling repository boxcar/raring
32737f8072d0: Downloading [> ] 2.228 MB/149.7 MB 12m29s
And end something like:
Step 20 : CMD ["/bin/bash", "/start.sh"]
---> Running in db53e215e2fc
---> 3f3f6489c700
Successfully built 3f3f6489c700
Once the project is built, we will start it and forward ports from the container to the host system, so that the Docker container’s site can be accessed through port 8000 of the host system. So, if you want to see it from the computer that you’ve installed it on, you could go to ‘HTTP://127.0.0.1:8000’. Alternatively, if your host system is already running a webserver, we could use SSHFS to mount the container’s files within the web-space of the host system.
In this example, however, we’ll just forward the ports and mount the project locally (using SSHFS) so we can easily edit the files perhaps using a graphical IDE such as NetBeans or Eclipse.
Okay, time to start our Docker image and find its IP address (so we can mount its files):
DID=$(docker run -p 8000:80 -d $ME/wordpress)
DIP=$(docker inspect $DID | grep IPAddress | cut -d '"' -f 4)
docker logs $DID| grep 'ssh user password:' --color
Copy the SSH password and we will make a local directory to access the WordPress installation of our containter.
cd ~
mkdir largo.mount.from.docker.container
sshfs user@$DIP:/var/www $HOME/largo.mount.from.docker.container
cd largo.mount.from.docker.container
PROJECT=$(pwd -P)
Now, we can visit the WordPress installation and finish setting up. From the host machine, it should be ‘HTTP://127.0.0.1:8000’. There you can configure Title, Username, Password, et cet. and finish installing WordPress.
Now, let’s get us some Largo! Since this is a test project, we’ll sacrifice security to make things easy. Our Docker WordPress site isn’t ready for us to easily install the Largo parent theme, so we’ll make the web directory writable by everybody. Generally, this is not a practice I would condone. It’s okay while we’re experimenting but permissions are very important on live systems!
Lastly, we’ll download and install Largo and the Largo child theme stub.
ssh user@$DIP 'sudo chmod -R 777 /var/www'
wget https://github.com/INN/Largo/archive/master.zip -O $PROJECT/wp-content/themes/largo.zip
unzip $PROJECT/wp-content/themes/largo.zip -d $PROJECT/wp-content/themes/
mv $PROJECT/wp-content/themes/Largo-master $PROJECT/wp-content/themes/largo
wget http://largoproject.wpengine.netdna-cdn.com/wp-content/uploads/2012/08/largo-child.zip -O $PROJECT/wp-content/themes/largo-child.zip
unzip $PROJECT/wp-content/themes/largo-child.zip -d $PROJECT/wp-content/themes
rm -rf $PROJECT/wp-content/themes/__MACOSX/
We are now ready to customize our Project Largo child theme!
Tags: Docker, Git, INN, Project Largo, SSHFS, Ubuntu, WordPress
Permalink: 20140217.project.largo.docker
Thu, 13 Jun 2013
Last we were discussing the structure and design of your own CLI-centric blog platform, we had some crude methods of starting and resuming posts before publishing.
Today, let’s explore a little more into setting up a bloging-friendly environment because we need to either make the experience of blogging easy or we’ll grow tired of the hassle and lose interest.
We can reasonably anticipate that we won’t want to beleaguered with repetitious typing of HTML bits. If we’re going to apply paragraph tags, hyperlinks, codeblocks, etc. with any frequency, that task is best to be simplified. Using Vim as our preferred editor, we will use Tim Pope’s brilliant plug-ins ‘surround’ and ‘repeat’, combined with abbreviations to take away the tedium.
The plug-ins just need dropped into your Vim plugin directory (~/.vim/plugin/
). The directory may not exist if you don’t have any plug-ins yet. That’s no problem, though. Let’s grab the plugins:
cd ~/.vim/
wget "http://www.vim.org/scripts/download_script.php?src_id=19287" -O surround.zip
wget "http://www.vim.org/scripts/download_script.php?src_id=19285" -O repeat.zip
Expand the archives into the appropriate directories:
unzip surround.zip
unzip repeat.zip
Ta-da! Your Vim is now configured to quickly wrap (surround) in any variety of markup. When working on a blog, you might use <p>
tags a lot by putting your cursor amid the paragraph and typing yss<p>
. The plug-in will wrap it with opening and closing paragraph tags. Move to your next paragraph and then press .
to repeat.
That out of the way, let’s take advantage of Vim’s abbreviations for some customization. In our .vimrc
file, we can define a few characters that Vim will expand according to their definition. For example, you might use:
ab <gclb> <code class="prettyprint lang-bsh linenums:1">
Then, any time you type <gclb>
and bress <enter>, you’ll get:
<code class="prettyprint lang-bsh linenums:1">
The next time that we take a look at blogitecture, we will focus on making the posts convenient to manage from our CLI.
Tags: abbreviations, blogitecture, repeat.vim, surround.vim, Vim
Permalink: 20130613.blogitechture.continued
Thu, 23 May 2013
Working on remote servers, some tools are practically ubiquitous — while others are harder to come by. Even if you’ve the authority to install your preferred tools on every server you visit, it’s not always something you want to do. If you’ve hopped on to a friend’s server just to troubleshoot a problem, there is little reason to install tools that your friend is not in the habit of using. Some servers, for security reasons, are very tightly locked down to include only a core set of tools, to complicate the job of any prying intruders. Or perhaps it is a machine that you normally use through a graphical interface but on this occasion you need to work from the CLI.
These are very compelling reasons to get comfortable, at the very least, with tools like Vim
, mail
, grep
and sed
. Eventually, you’re likely to encounter a situation where only the classic tools are available. If you aren’t competent with those tools, you’ll end up facing the obstacle of how to get files from the server to your local environment where you can work and, subsequently, how to get the files back when you’re done. In a secured environment, this may not be possible without violating protocols.
Let’s take a look at how we can build a makeshift system monitor using some common tools. This particular configuration is for a server running PHP, MySQL and has the tools Htop and mytop installed. These can easily be replaced with top
and a small script to SHOW FULL PROCESSLIST
, if needed. The point here is illustrative, to provide a template to be modified according to each specific environment.
(Note: I generally prefer tmux to Gnu Screen but screen
is the tool more likely to be already installed, so we’ll use it for this example.)
We’re going to make a set of windows, by a configuration file, to help us keep tabs on what is happening in this system. In so doing, we’ll be using the well-known tools less
and watch
. More specifically, less +F
which tells less
to “scroll forward”. Other words, less
will continue to read the file making sure any new lines are added to the display. You can exit this mode with CTRL+c
, search the file (/), quit(q) or get back into scroll-forward mode with another uppercase F.
Using watch
, we’ll include the “-d” flag which tells watch we want to highlight any changes (differences).
We will create a configuration file for screen
by typing:
> vim monitor.screenrc
In the file, paste the following:
# Screen setup for system monitoring
# screen -c monitor.screenrc
hardstatus alwayslastline
hardstatus string '%{= kG}[ %{G}%H %{g}][%= %{=kw}%?%-Lw%?%{r}(%{W}%n*%f%t%?(%u)%?%{r})%{w}%?%+Lw%?%?%= %{g}][%{B}%Y-%m-%d %{W}%c %{g}]'
screen -t htop 0 htop
screen -t mem 1 watch -d "free -t -m"
screen -t mpstat 2 watch -d "mpstat -A"
screen -t iostat 3 watch -d "iostat"
screen -t w 4 watch -d "w"
screen -t messages 5 less +F /var/log/messages
screen -t warn 6 less +F /var/log/warn
screen -t database 7 less +F /srv/www/log/db_error
screen -t mytop 8 mytop
screen -t php 9 less +F /srv/www/log/php_error
(Note: -t
sets the title, then the window number, followed by the command running in that window)
Save the file (:wq
) or, if you’d prefer, you can grab a copy by right-clicking and saving this file.
Then we will execute screen
using this configuration, as noted in the comment:
> screen -c monitor.screenrc
Then you can switch between windows using CTRL+a, n
(next) or CTRL+a, p
(previous).
I use this technique on my own computers, running in a TTY different from the one used by X. If the graphical interface should get flaky, I can simply switch to that TTY (e.g., CTRL+ALT+F5
) to see what things are going on — and take corrective actions, if needed.
Tags: GNU-Screen, Htop, iostat, mem, mpstat, MySQL, mytop, PHP, system-monitor, watch, who
Permalink: 20130523.gnu.screen.system.monitor
Wed, 15 May 2013
There may be times when you find your Git repository burdened with scads of untracked files left aside while twiddling, testing bug patches, or what-have-youse.
For the especially scatter-brained among us, these things can go unchecked until a day when the useful bits of a git status
scroll off the screen due to utterly unimportant stuff. Well, hopefully unimportant.
But we’d better not just cleave away everything that we haven’t checked in. You wonder:
What if there’s something important in one of those files?
You are so right!
Let’s fix this!
Firstly, we want a solution that’s reproducible. Only want to invent this wheel once, right?
Let’s begin with the play-by-play:
Git, we want a list of what isn’t tracked:
git ls-files -o --exclude-standard -z
We’ll back these files up in our home directory (~
), using CPIO
but we don’t want a poorly-named directory or finding anything will become its own obstacle. So we’ll take use the current date (date +%Y-%m-%d
), directory (pwd
) and branch we’re using (git branch
) and we’ll twist all of it into a meaningful, but appropriate, directory name using sed
.
git ls-files -o --exclude-standard -z | cpio -pmdu ~/untracked-git-backup-`date +%Y-%m-%d`.`pwd | sed 's,^\(.*/\)\?\([^/]*\),\2,'`.`git branch | grep "*" | sed "s/* //"`/
Then Tell Git to remove the untracked files and directories:
git clean -d -f
Ahhhh… Much better. Is there anything left out? Perhaps. What if we decide that moving these files away was a mistake? The kind of mistake that breaks something. If we realize right away, it’s easily-enough undone. But what if we break something and don’t notice for a week or two? It’d probably be best if we had an automated script to put things back the way they were. Let’s do that.
Simple enough. We’ll just take the opposite commands and echo
them into a script to be used in case of emergency.
Create the restore script (restore.sh), to excuse faulty memory:
echo "(cd ~/untracked-git-backup-`date +%Y-%m-%d`.`pwd | sed 's,^\(.*/\)\?\([^/]*\),\2,'`.`git branch | grep "*" | sed "s/* //"`/; find . -type f \( ! -iname 'restore.sh' \) | cpio -pdm `pwd`)" > ~/untracked-git-backup-`date +%Y-%m-%d`.`pwd | sed 's,^\(.*/\)\?\([^/]*\),\2,'`.`git branch | grep "*" | sed "s/* //"`/restore.sh
Make the restore script executable:
chmod u+x ~/untracked-git-backup-`date +%Y-%m-%d`.`pwd | sed 's,^\(.*/\)\?\([^/]*\),\2,'`.`git branch | grep "*" | sed "s/* //"`/restore.sh
Lastly, the magic, compressed into one line that will stop if any command does not report success:
a='untracked-git-backup-'`date +%Y-%m-%d`.`pwd | sed 's,^\(.*/\)\?\([^/]*\),\2,'`.`git branch | grep "*" | sed "s/* //"`; git ls-files -o --exclude-standard -z | cpio -pmdu ~/$a/ && git clean -d -f && echo "(cd ~/$a/; find . -type f \( ! -iname 'restore.sh' \) | cpio -pdm `pwd`)" > ~/$a/restore.sh && chmod +x ~/$a/restore.sh; unset a
Tags: CLI, find, Git, sed, untracked
Permalink: 20130515.git.untracked.mess
Mon, 13 May 2013
Documentation for this one seems a bit hard to come by but it is one of the things I love about Zsh.
I’ve seen many .bashrc
files that have things like:
alias www='cd /var/www'
alias music='cd /home/j0rg3/music'
And that’s a perfectly sensible way to make life a little easier, especially if the paths are very long.
In Zsh, however, we can use the hash
command and the shortcut we get from it works fully as the path. Other words, using the version above, if we want to edit ‘index.html’ in the ‘www’ directory, we would have to issue the shortcut to get there and then edit the file, in two steps:
> www
> vim index.html
The improved version in .zshrc
would look like:
hash www=/var/www
hash -d www=/var/www
Then, at any time, you can use tilde (~) and your shortcut in place of path.
> vim ~www/index.html
Even better, it integrates with Zsh’s robust completions so you can, for example, type cd ~www/
and then use the tab key to cycle through subdirectories and files.
On this system, I’m using something like this:
(.zshrc
)
hash posts=/home/j0rg3/weblog/posts
hash -d posts=/home/j0rg3/weblog/posts
Then we can make a function to create a new post, to paste into .zshrc
. Since we want to be able to edit and save, without partial posts becoming visible, while we are working, we’ll use an extra .tmp
extension at the end:
post() { vim ~posts/`date +%Y-%m`/`date +%Y%m%d`.$1.txt.tmp }
[ In-line date
command unfamiliar? See earlier
explanation ]
But, surely there is going to be a point when we need to save a post and finish it later. For now, let’s assume that only a single post will be in limbo at any time. We definitely don’t want to have to remember the exact name of the post — and we don’t want to have hunt it down every time.
We can make those things easier like this:
alias resume="vim `find ~posts/ -name '*.txt.tmp'`"
Now, we can just enter
resume
and the system will go find the post we were working on and open it up for us to finish.
The file will need the extension renamed from
.txt.tmp
to only
.txt
to publish the post but, for the sake of brevity, we’ll think about that (and having multiple posts in editing) on another day.
Tags: blogitecture, CLI, find, hash, Zsh
Permalink: 20130513.zsh.and.hash
Tue, 07 May 2013
Thanks for visiting my little spot on the web. This is a Blosxom ‘blog which, for those who don’t know, is a CGI written in Perl using the file-system (rather than a database).
To the CLI-addicted, this is an awesome little product. Accepting, of course, that you’re going to get under the hood if you’re going to make it the product you want. After some modules and hacking, I’m pleased with the result.
My posts are just text files, meaning I start a new one like:
vim ~posts/`date +%Y%m%d`.brief.subject.txt
Note: the back-ticks (`) tell the system that you want to execute the command between ticks, and dynamically insert its output into the command.
In this case, the command date
with these parameters:
- (+) we’re going to specify a format
- (%Y) four-digit year
- (%m) two-digit month
- (%d) two-digit day
That means the command above will use Vim to edit a text file named ‘20130507.brief.subject.txt’ in the directory I have assigned to the hash
of ‘posts’.
(using hash
this way is a function of Zsh that I’ll cover in another post)
In my CLI-oriented ‘blog, I can sprinkle in my own HTML or use common notation like wrapping a word in underscores to have it
underlined, forward-slashes for
italics and asterisks for
bold.
Toss in a line that identifies tags and, since Perl is the beast of Regex, we pick up the tags and make them links, meta-tags, etc.
Things here are likely to change a lot at first, while I twiddle with CSS and hack away at making a Blosxom that perfectly fits my tastes — so don’t be too alarmed if you visit and things look a tad wonky. It just means that I’m tinkering.
Once the saw-horses have been tucked away, I’m going to take the various notes I’ve made during my years in IT and write them out, in a very simple breakdown, aimed at sharing these with people who know little about how to negotiate the command line. The assumption here is that you have an interest in *nix/BSD. If you’ve that and the CLI is not a major part of your computing experience, it probably will be at some point. If you’re working on systems remotely, graphical interfaces often just impede you.
Once you’ve started working on remote machines, the rest is inevitable. You can either remember how to do everything two ways, through a graphical interface and CLI — or just start using the CLI for everything.
So let’s take a little journey through the kinds of things that make me love the CLI.
Tags: blogitecture, Blosxom, BSD, CGI, CLI, firstpost, hash, Perl, Vim, Zsh
Permalink: 20130507.greetings