Skip to content

March 30, 2012

15

Changes to make CutyCapt bypassing ssl certificate confirmation

by Joe Kuan

I need to use CutyCapt to run with https url on server side. However, it doesn’t support https url. A patch for bypassing the SSL certificate confirmation has been submitted on this page (and other additional features). However that change has never been pulled to the main release. So I tried to apply the patch to the source, the patch process didn’t work and the build failed.

[root@AppQoS /home/appqos/CutyCapt]# patch < /tmp/patch.diff
Hmm...  Looks like a unified diff to me...
The text leading up to this was:
--------------------------
|Index: CutyCapt.hpp
|===================================================================
|--- CutyCapt.hpp	(revision 2)
|+++ CutyCapt.hpp	(working copy)
--------------------------
Patching file CutyCapt.hpp using Plan A...
Hunk #1 failed at 27.
Hunk #2 succeeded at 50 with fuzz 2 (offset 2 lines).
1 out of 2 hunks failed--saving rejects to CutyCapt.hpp.rej
Hmm...  The next patch looks like a unified diff to me...
The text leading up to this was:
--------------------------
|Index: CutyCapt.cpp
|===================================================================
|--- CutyCapt.cpp	(revision 2)
|+++ CutyCapt.cpp	(working copy)
--------------------------
Patching file CutyCapt.cpp using Plan A...
Hunk #1 failed at 120.
Hunk #2 succeeded at 273 (offset 56 lines).
Hunk #3 failed at 338.
Hunk #4 failed at 359.
Hunk #5 succeeded at 346 with fuzz 1 (offset 28 lines).
Hunk #6 succeeded at 561 (offset 103 lines).
Hunk #7 failed at 581.
4 out of 7 hunks failed--saving rejects to CutyCapt.cpp.rej
done

So I examine the patch content and thankfully the changes are simple enough to apply manually. Here is what you need to change the CutyCapt source. Presume you already have CutyCapt built successfully.

On CutyCapt.hpp file, add the highlighted line

  CutyCapt(CutyPage* page,
           const QString& output,
           int delay,
           OutputFormat format,
           const QString& scriptProp,
           const QString& scriptCode);

private slots:
  void DocumentComplete(bool ok);
  void InitialLayoutCompleted();
  void JavaScriptWindowObjectCleared();
  void Timeout();
  void Delayed();
  void handleSslErrors(QNetworkReply* reply, QList<QSslError> errors);

private:

Then on CutyCapt.cpp, add the following highlighted lines

CutyCapt::CutyCapt(CutyPage* page, const QString& output, int delay, OutputFormat format,
                   const QString& scriptProp, const QString& scriptCode) {
  mPage = page;
  mOutput = output;
  mDelay = delay;
  mSawInitialLayout = false;
  mSawDocumentComplete = false;
  mFormat = format;
  mScriptProp = scriptProp;
  mScriptCode = scriptCode;
  mScriptObj = new QObject();

  // This is not really nice, but some restructuring work is
  // needed anyway, so this should not be that bad for now.
  mPage->setCutyCapt(this);

  // Ignore SSL errors
 QNetworkAccessManager* mManager = mPage->networkAccessManager();
  connect(mManager, SIGNAL(sslErrors(QNetworkReply*,QList<QSslError>)),
            this, SLOT(handleSslErrors(QNetworkReply*,QList<QSslError>)));
}

void CutyCapt::handleSslErrors(QNetworkReply* reply, QList<QSslError> errors) {
    reply->ignoreSslErrors();
}

void
CutyCapt::InitialLayoutCompleted() {
  mSawInitialLayout = true;

  if (mSawInitialLayout && mSawDocumentComplete)
    TryDelayedRender();
}

Build the program and this should work as a treat on https urls.

15 Comments Post a comment
  1. Apr 26 2012

    The HTML has messed up in the above post. After every instance of Qlist, there should be a <QSslError> so that it looks like (for eg.):

    void handleSslErrors(QNetworkReply* reply, Qlist<QSslError> errors);

    There are 4 places that you need to make this change.

    Otherwise you’ll get errors when you try to compile:
    CutyCapt.hpp:51: error: âQListâ is not a type
    CutyCapt.cpp:179: error: âQListâ is not a type

    See the original patch diff to see exactly what I mean / what changes you need to make.

    Thanks Joe – this fixed the problem for me!

    Reply
    • Joe Kuan
      Apr 26 2012

      Yeah, I know. I will need to use the proper html tag rather than this fancy syntaxhighlighter for this piece of code.

      Reply
  2. Josephc
    Jun 12 2012

    would it be possible to post the exe file after you have applied the changes?
    i have tried to compile cutycapt even without the changes and i get all sorts of errors.

    Reply
  3. Josephc
    Jun 12 2012

    Sorry my manners: Please if it is possible to post the exe file after applying the changes and compiling. Thanks :)

    Reply
    • Joe Kuan
      Jun 12 2012

      It’s ok. I have only built CutyCapt on FreeBSD. However, have u got Qt already installed? That’s more complicated to build & install. If so, then pls let me know your email address. I post you the binaries.

      Thanks
      Joe

      Reply
      • Josephc
        Jun 12 2012

        Thanks Joe that is very kind of you.
        yes I have installed and am running QT creator. when i run and build the application from the QTcreatoer it works like a charm but when i try to run it outside the creator it doesnt seem to work. i tried a few variations and been trying to figure out what dlls i am missing.
        anyhow my email is joecopty@gmail.com Thanks a million
        Joe

      • Josephc
        Jun 13 2012

        Ok never mind after much grief i finally got it. I was missing some dlls for openssl…
        Thank you for your help.
        Joe

  4. Simon
    Dec 31 2012

    Hi Joe, would you be able to email or upload the compiled file with the SSl enhancements online please? Would be a massive help as I haven’t stepped into QT or C++ programming as yet.

    Reply
    • Joe Kuan
      Dec 31 2012

      I don’t think I email you a compiled version and it will work straight away. You certainly need to get QT installed as CutyCapt dynamically linked to the library. I only got compiled executable for the old FreeBSD 8.2.

      Reply
      • Simon
        Jan 1 2013

        Hi, thanks for your reply. I’ve finally managed to set up the QT environment and tried applying your documented changes to the original files. After rebuilding the file (and copying all the missing dlls to the directory with the new executable) I’ve tried to run https url,but got a white screenshot, just as before. If you have successfully managed to update CutyCapt to generate screenshots for the websites with ssl applied, could you please upload or share the new exe file in any other possible way?

      • Joe Kuan
        Jan 1 2013

        Sorry, I never have compiled CutyCapt on Windows, so I am not the best person to give u advice.

  5. matt
    Jan 10 2014

    joe can you email me your uncompiled source code you put together? G1ldedM1n1on@gmail.com

    Reply
    • Joe Kuan
      Jan 17 2014

      Emailed the code to you. I only compiled it on FreeBSD 8 and 9. So you may need to make some changes for Linux.

      Joe

      Reply
  6. Jun 2 2015

    Hi, i installed cutycapt via the apt-get install cutycapt command, is there a way to apply the patch via apt-get ?

    Reply
    • Joe Kuan
      Jun 9 2015

      No. I am afraid you have to do it the hard way.

      Reply

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Note: HTML is allowed. Your email address will never be published.

Subscribe to comments

%d bloggers like this: